Triggers

The **trigger tool** is one of the most powerful tools available in JollyWorld. It allows you to program actions when certain conditions are met.

Triggers are yellow transparent objects generated by the trigger tool. They can be placed in the Editor and programmed to perform certain actions

## Functions

### Appearance

Triggers can either be boxes or circles. They cannot be changed from a circle to a box or vice versa.

Box triggers can be moved by dragging with the mouse or by using the arrow keys, resized by pressing W A S D, or rotated by pressing Z and X, or by changing the appropriate fields in the dropdown menu. They cannot have vertices moved, added, or removed. Circle triggers can only be scaled along the radius, so they will always be round.

### Conditions

When a certain target collides with a trigger, it will activate. These conditions include.

* mainCharacter: Triggers when touched by the main character
* anyCharacter: Triggers if any character touches
* anyButMainCharacter: Triggers if any character touches it
* allObjects Triggers if any body touches it
* attachedTargetsOnly: Only activates if an object attached to a trigger touches it
* click: Activates when clicked on by the mouse.
* keyDown: Activates when a certain key is pressed. It supports these keys
	+ The number keys from 0-9
	+ Enter
	+ Shift (both Shift keys)
	+ Control
	+ Alt
	+ Left, Right, Up, and Down arrow keys,
	+ Delete
	+ Command (or Windows key for Windows)
	+ Space
	+ Every letter key except P, which pauses the game, and R, which restarts the game.
* keyUp: Activates when a certain key is released. The same keys are supported
* triggers: Activates only when activated by another trigger. Triggers can also be activated by seven-segment counters by linking them together. When the condition of the counter is met, the trigger is activated regardless of its prior conditions.

### Repeating

* Once: Activates once, then deletes itself
* Multiple: Activates when the target condition is met whenever
* Continuously: Triggers multiple times when the target condition is met without having to deactivate.

### Delaying

Delay time is measured in seconds. By default it is set to 0.

* Delay: Delays the time between a trigger's conditions being set and the trigger activating.
* Repeat delay: Delays the time between each activation of a continuous trigger. Setting it to 0 will cause it to trigger every frame.

### Enabling triggers

This determines whether a trigger is enabled or disabled. A disabled trigger will not activate even if the conditions are met.

### Following

By themselves triggers do not move. This function allows them to be attached to other objects.

* None: Does not move
* Player, Follows the player
* First target: Follows only the first target.

### Random Target

When this is set, the trigger will only activate one attached target chosen randomly as opposed to activating all of them.

### Checkpoint Persistent

When this is set, when the trigger had activated before touching a checkpoint, it will trigger whenever you restart the level.

## Actions

These are the things that a trigger can do to an attached target once activated. It can affect all objects except graphics or groups consisting only graphics

### All objects

Only 'Empty' and 'Destroy' can be used on joints

* **Empty**: Does nothing
* **Impulse**: Launches a non-static object in a certain direction. Also does not affect graphics, text, triggers, or anything else not affected by gravity.
	+ **LinearForce**: Changes how much the object will be launched
	+ **Relative**: If true, the object will be launched relative to its own rotation.
	+ **Direction**: The direction the object will be launched
	+ **RotationalForce**: Changes how much the object rotates
* **setPosition**: Changes the object's X and Y position
	+ **fixed**: Sets the object's position to a fixed amount
	+ **add**: Moves the object by a certain amount.
	+ **relative**: Sets the position relative to the trigger's own position
* **setRotation**: Changes the rotation of an object
	+ **fixed**: Sets the object's rotation to a fixed amount
	+ **add**: Rotates the object clockwise by a certain amount. If the value is negative it rotates counter-clockwise
	+ **relative**: Sets the rotation relative to the trigger's own rotation
* **setVisibility**: Changes the visibility of an object
	+ **Toggle**: Changes the object's visibility from on to off and vice versa
	+ **SetVisible**: If on, set to visible. If off, set to invisible
* **setOpacity**: Changes the object's transparency from a value between 0 and 1, correct to 2 decimal places
	+ **Fixed**: Sets the opacity to a fixed amount,
	+ **Add**: Makes the object more opaque
	+ **Subtract**: Makes the object more transparent
* **Destroy**: Destroys the object.

### Main Character

* **DealDamage**: Deals a fixed amount damage to the main character. This does not remove his/her limbs. If
* **SetColorMatrix**: Sets his/her colour matrix. This brings up the color matrix editor. This does not affect the level's matrix.
* **setFlipped**: Flips the main character left and right
	+ Toggle: Flips the main character from left to right and vice versa
	+ Flipped: Changes the main character's flip status. If true, he/she faces left. If false, he/she faces right.

### Bodies, body groups, and mixed groups

* **SetCameraTarget**: Makes the camera focus on the body
* **SetCollision**: Changes the body's collision.
* **SetStatic**: Changes if the body is affected by gravity
	+ **Toggle**: Changes it from static to not static and vice versa
	+ **setStatic**: If true, it will not be affected by gravity. If false, it will be affected by gravity

### Graphics and graphic groups

* **SetMirrored**: Mirrors the graphic left and right. Also affects mixed groups. Does not flip vertically.
	+ Toggle:
* **SetColorMatrix**: Sets the graphic's color matrix. This brings up the color matrix editor. This does not affect the level's matrix.

### Cannons and crossbows

* **Shoot**: Makes the cannon or crossbow fire a projectile

### Drone bombs

* **SetActive**: Activates or deactivates the drone.
* **Explode**: Makes the bomb explode
* **SetWayPoint**: Changes the drone's target

### Explosive barrels and grenades

* **SetActive**: Activates or deactivates the explosive.
* **Explode**: Makes it explode

### Animators

* **SetProgress**: Moves the animator's target to a certain point along the path
* **SetClockwise**: Changes the animator's direction from clockwise to counter-clockwise and vice versa
* **SetAnimating**: Turns on and off the animator
* **SetDuration**: Speeds up and slows down the animator. A shorter duration leads to a faster speed for the animator, while a longer duration leads to a slower speed

### Triggers

* **Trigger**: Activates the trigger regardless of its conditions
* **SetEnabled**: Enables or disables the trigger
* **SetFollowPlayer**: Makes the trigger follow the player

### Jets

* **EngineOn**: Turns on and off the jet's engine, making it move.

### NPCs

* **SetAwake**: Changes whether the NPC will be awake or not.
* **SetInteractivity**: Changes whether the NPC can interact with the level
	+ **Interactive**: The NPC is affected by gravity and can be moved or harmed by other objects.
	+ **Invincible**: The NPC is affected by gravity and other objects, but cannot be killed
	+ **Non-interactive**: The NPC is unaffected by gravity or other objects

### Seven-Segments

* **Increase**: Increases the counter by 1
* **Decrease**: Decreases the counter by 1
* **SetNumber**: Sets the counter to a selected number between 0 and 9
* **SetRandom**. Sets the counter to a random number between 0 and 9

### World Actions

These can be activated without setting a target.

* **SetCameraZoom**: Changes the camera zoom from a number between 0.1 and 2. Defaults to 1.
* **ResetCameraTarget**: If another object was made the camera target, this action changes the camera target back to the main character.
* **SetWin**: Automatically completes the level. This will not register the player's time to the Leaderboard
* **SetLose**: Automatically fails the level without needing to kill the player.
* **SetGameSpeed**: Changes the game speed. Defaults to 1, the regular game speed.
* **SetCameraColorMatrix**: This brings up the color matrix editor. This affect the level, graphics and the main character.
* **PlaySFX**: Plays a sound effect. There are two buttons to test or stop the sound.
	+ **Volume**: Sets the sound's volume from 0 to 2, with 1 as the default.
	+ **Pitch**: Sets the sound's pitch from 0.1 to 4, with 1 as the default
	+ **RandomPitchOffset**: Randomly changes the pitch of the sound by a certain amount.
* **MidiControls**: Plays or stops the MIDI song imported into the level
	+ **Play**: Plays the MIDI
	+ **Stop**: Stops the MIDI
* **PlayMIDIInstrument**: Plays a specific instrument from the imported MIDI. Includes a button to test the sound
	+ **Note**: Sets the note played
	+ **BPM**: Sets the beats per minute for the note
	+ **Length**: Sets the amount of tones the note will be played. Defaults to one major second (1)
* **SetScreenShake**: Shakes the screen temporarily
	+ **Amplitude**: A value from 0-100 that changes how far the screen moves while shaking.