Libraries.Interface.Vibration.Vibration Documentation

The Vibration class can be used to start vibration patterns on devices with a vibration motor.

Example Code

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:VibrateForever()
    end
end

Inherits from: Libraries.Language.Object

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

Knock(integer repetitions)

This method vibrates according to a preset pattern, which has two quick vibrations followed by a long pause and a final vibration. Repeats the pattern for the amount of times specified.

Parameters

  • integer repetitions: The amount of times for the pattern to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:Knock(3)
    end
end

KnockForever()

This method vibrates according to a preset pattern, which has two quick vibrations followed by a long pause and a final vibration. Repeats the pattern until the Stop() action is called.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:KnockForever()
    end
end

KnockOnce()

This method vibrates according to a preset pattern, which has two quick vibrations followed by a long pause and a final vibration.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:KnockOnce()
    end
end

QuickPulse(number seconds)

This method vibrates according to a preset pattern, which has quick vibrations in rapid succession, repeating for the specified number of seconds.

Parameters

  • number seconds: The number of seconds for the vibration to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:QuickPulse(2.5)
    end
end

QuickPulseForever()

This method vibrates according to a preset pattern, which has quick vibrations with short pauses in between, repeating until the Stop() action is called.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:QuickPulseForever()
    end
end

Rumble(number seconds)

This method vibrates according to a preset pattern, creating a low-intensity vibration with very short pauses, repeating for the specified number of seconds.

Parameters

  • number seconds: The number of seconds for the vibration to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:Rumble(2.5)
    end
end

RumbleForever()

This method vibrates according to a preset pattern, creating a low-intensity vibration with very short pauses, repeating until the Stop() action is called.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:RumbleForever()
    end
end

SlowPulse(number seconds)

This method vibrates according to a preset pattern, which has slow vibrations with relatively long pauses in between, repeating for the specified number of seconds.

Parameters

  • number seconds: The number of seconds for the vibration to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:SlowPulse(2.5)
    end
end

SlowPulseForever()

This method vibrates according to a preset pattern, which has slow vibrations with relatively long pauses in between, repeating until the Stop() action is called.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:SlowPulseForever()
    end
end

Stop()

Cancels the current vibration.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action ContinuedTouch(TouchEvent event)
        if (event:GetX() >= 200 and event:GetX() <= 300) and (event:GetY() >= 900 and event:GetY() <= 1600)
            vibrator:VibrateAtFrequency(10)
        elseif (event:GetX() >= 200 and event:GetX() <= 300) and (event:GetY() >= 200 and event:GetY() <= 900)
            vibrator:VibrateAtFrequency(2.5)
        else
            vibrator:Stop()
        end
    end
end

Vibrate(number seconds)

This method turns on the motor, vibrating constantly at maximum intensity for the number of seconds specified.

Parameters

  • number seconds: The number of seconds for the vibration to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:Vibrate(2.5)
    end
end

Vibrate(number seconds, number intensity)

This method turns on the motor, vibrating constantly for the number of seconds specified at the given intensity. The intensity is expected to be a number between 0.0 and 1.0, representing a percentage of the maximum intensity allowed by the device.

Parameters

  • number seconds: The number of seconds for the vibration to play.
  • number intensity: The intensity of the vibration, given by a number between 0.0 and 1.0, which represents the percentage of maximum intensity at which to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:Vibrate(2.5, 0.5)
    end
end

Vibrate(Libraries.Interface.Vibration.VibrationArray vibrationArray, integer repetitions)

This method plays a vibration pattern created with a VibrationArray. Repeats the pattern for the amount of times specified.

Parameters

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Interface.Vibration.VibrationArray
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        VibrationArray pattern

        patter:Add(1.5, 0.5)
        pattern:Add(0.5, 0.0)
        pattern:Add(1)

        vibrator:Vibrate(pattern, 5)
    end
end

VibrateAtFrequency(number seconds, number frequency)

Plays a vibration at the given frequency for the given number of seconds. The frequency is measured in Hertz (Hz).

Parameters

  • number seconds: The number of seconds for the vibration to play.
  • number frequency: The frequency, measured in Hertz (Hz), for the vibration to play at.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:VibrateAtFrequency(2, 2.5)
    end
end

VibrateAtFrequencyForever(number frequency)

Plays a vibration at the given frequency, repeating until the Stop() action is called. The frequency is measured in Hertz (Hz).

Parameters

  • number frequency: The frequency, measured in Hertz (Hz), for the vibration to play at.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:VibrateAtFrequencyForever(2.5)
    end
end

VibrateForever(Libraries.Interface.Vibration.VibrationArray vibrationArray)

This method plays a vibration pattern created with a VibrationArray, repeating until the Stop() action is called.

Parameters

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Interface.Vibration.VibrationArray
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        VibrationArray pattern

        patter:Add(1.5, 0.5)
        pattern:Add(0.5, 0.0)
        pattern:Add(1)

        vibrator:VibrateForever(pattern)
    end
end

VibrateForever()

This method turns on the motor, vibrating constantly at maximum intensity, repeating until the Stop() action is called.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:VibrateForever()
    end
end

VibrateForever(number intensity)

This method turns on the motor, vibrating constantly at the given intensity, repeating until the Stop() action is called. The intensity is expected to be a number between 0.0 and 1.0, representing a percentage of the maximum intensity allowed by the device.

Parameters

  • number intensity: The intensity of the vibration, given by a number between 0.0 and 1.0, which represents the percentage of maximum intensity at which to play.

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        vibrator:VibrateForever(0.5)
    end
end

VibrateOnce(Libraries.Interface.Vibration.VibrationArray vibrationArray)

This method plays a vibration pattern created with a VibrationArray.

Parameters

Example

use Libraries.Interface.Vibration.Vibration
use Libraries.Interface.Vibration.VibrationArray
use Libraries.Game.Game
use Libraries.Interface.Events.TouchListener
use Libraries.Interface.Events.TouchEvent

class Main is Game, TouchListener

    Vibration vibrator

    action Main
        StartGame()
    end

    action CreateGame
        AddTouchListener(me)
    end

    action BeganTouch(TouchEvent event)
        VibrationArray pattern

        patter:Add(1.5, 0.5)
        pattern:Add(0.5, 0.0)
        pattern:Add(1)

        vibrator:VibrateOnce(pattern)
    end
end