Callbacks
Introduction
These functions set conditions, such as when players press a key designated by the script developer or arrive at a specific point, and operate when the condition is satisfied.
runLater
Function operates after specified time (in seconds)
addOnTileTouched
Function operates when a player gets to the specified X and Y coordinates
addOnLocationTouched
Function operates when a player gets to the specified ‘designated area’
addOnKeyDown
Function operates when a player presses the specified key
setTimeout
Function operates at a specified time interval (ms)
setInterval
Function operates after the specified amount of time (ms)
addMobileButton
Function operates after pressing a custom button in the mobile environment
putMobilePunch
Function to add a punch button in the mobile environment
putMobilePunchWithIcon
Function to add a punch button using a loaded image
📚 Description and Example
Callbacks at a Glance
runLater
App.runLater(function(){}, time: number);
This executes a callback function after a period of time (in seconds).
Parameter
time
Number
Calls the function after a set amount of time (in seconds).
Example
Display a message five seconds after an app starts.
addOnTileTouched
App.addOnTileTouched(x: integer, y: integer, function(player){})
This executes a callback function when a player gets to the designated X and Y coordinates.
Parameter
x, y
Integer
The designated X and Y coordinates
Example
Display a message when a player gets to the designated coordinates.
addOnLocationTouched
addOnLocationTouched(name: string, function(player){})
This executes a callback function when a player gets to the designated area specified by the Map Editor.
Parameters
name
String
The name of the designated area specified by the Map Editor
player
Player
The player who gets to the designated area The parameter name can be changed arbitrarily
Example
Display a message when a player gets to the designated area.
addOnKeyDown
App.addOnKeyDown(keycode : number, function(player){});
This executes a callback when a player presses the specified key.
Parameters
keycode
Number
player
Player
The player who presses the specific key The player’s parameter names can be changed arbitrarily
Example
Display a message when a player presses “a” (a’s keycode: 65).
setTimeout
setTimeout(function(){}, time: number);
This executes a callback after time (ms).
Parameter
time
Number
Waiting time (ms) before executing a callback function
Example
Display a message 5 seconds after an app is executed.
setInterval
setInterval(function(){}, time: number);
This executes a callback at a specified time interval (ms).
Parameter
time
Number
Callback execution cycle (ms)
Example
Display a message every one second after an app is executed.
addMobileButton
App.addMobileButton( anchor: number, posX: number, posY: number, function(player){} )
This executes by pressing a custom button added in the mobile environment.
Parameters
anchor
Number
Use numbers for the locations of each mobile button TOP = 0, TOP_LEFT = 1, TOP_RIGHT = 2, MIDDLE = 3, MIDDLE_LEFT = 4, MIDDLE_RIGHT = 5, BOTTOM = 6, BOTTOM_LEFT = 7, BOTTOM_RIGHT = 8
posX
Number
X direction offset
posY
Number
Y direction offset
player
Player
The player who presses the mobile button
Example
Add a mobile button.
putMobilePunch
App.putMobilePunch(enable: boolean = true)
This adds a punch button in the mobile environment when "enable" is "true."
Parameter
enable
Boolean
Whether the mobile punch button is enabled ("true" is default)
Example
Add or delete the mobile punch button by pressing q.
putMobilePunchWithIcon
App.putMobilePunchWithIcon(icon: ScriptDynamicResource)
This function adds a punch button using a image loaded.
Parameter
icon
ScriptDynamicResource
Image resources loaded using App.loadSpriteSheet
Example
Add a punch button using a loaded image in the mobile environment by pressing q.
Appendix
Last updated