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
// Executes a callback function after time (in seconds)
App.runLater(callback, time: number)
// Executes a callback function when a player touches a tile at that location
App.addOnTileTouched(x: integer, y: integer, callback)
// Executes when a player comes in contact with a specific area
App.addOnLocationTouched(name: string, callback)
// Executes when a player presses a certain key
App.addOnKeyDown(keycode : number, callback);
// Executes a callback at a specified time interval (ms)
setTimeout(callback, time: number)
// Executes a callback after time (ms)
setInterval(callback, time: number)
// Executes a function after pressing a custom button in the mobile environment
App.addMobileButton(anchor: number, posX: number, posY: number, function(player){} )
// Adds or deletes a punch button in the mobile environment
App.putMobilePunch(enable: boolean = true)
// Adds a punch button using a image loaded
App.putMobilePunchWithIcon(icon: ScriptDynamicResource)
runLater
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.
App.onStart.Add(function () {
App.runLater(function() {
App.showCenterLabel("message");
}, 5);
});
addOnTileTouched
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.
// Calls the function when the player arrives at coordinates 5, 5
App.addOnTileTouched(5, 5, function (player) {
App.showCenterLabel(`${player.name} arrived at (5, 5)!`);
});
addOnLocationTouched
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.
// Executes when a player gets to the area named "myLocation"
App.addOnLocationTouched("myLocation", function(player){
App.showCenterLabel(`${player.name} has arrived at myLocation.`)
});
addOnKeyDown
This executes a callback when a player presses the specified key.
Parameters
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).
// Executes when a player presses "a"
App.addOnKeyDown(65, function(player){
App.sayToAll(`${player.name} has pressed "a".`)
});
setTimeout
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.
App.onStart.Add(function () {
setTimeout(function () {
App.sayToAll("Display message after 5 seconds");
}, 5000);
});
setInterval
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.
let time = 0;
App.onStart.Add(function () {
setInterval(function () {
App.sayToAll(`${++time} passed after app execution`);
}, 1000);
});
addMobileButton
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.
App.onStart.Add(function () {
// Bottom_Right
App.addMobileButton(8, 145, 75, function (player) {
App.sayToAll(`${player.name}, Bottom A`);
});
// Bottom_Right
App.addMobileButton(8, 145, -20, function (player) {
App.sayToAll(`${player.name}, Bottom B`);
});
// Top
App.addMobileButton(0, 0, 400, function (player) {
App.sayToAll(`${player.name}, TOP Bottom`);
});
// Top_Left
App.addMobileButton(1, 50, 400, function (player) {
App.sayToAll(`${player.name}, TOP_LEFT Bottom`);
});
// Top_right
App.addMobileButton(2, 50, 400, function (player) {
App.sayToAll(`${player.name}, TOP_RIGHT Bottom`);
});
// Middle
App.addMobileButton(3, 0, 100, function (player) {
App.sayToAll(`${player.name}, MIDDLE Bottom`);
});
// Middle_left
App.addMobileButton(4, 50, 100, function (player) {
App.sayToAll(`${player.name}, MIDDLE LEFT Bottom`);
});
// Middle_right
App.addMobileButton(5, 50, 100, function (player) {
App.sayToAll(`${player.name}, MIDDLE RIGHT Bottom`);
});
});
putMobilePunch
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.
let punchButton = false;
// Activates function when q is pressed
App.addOnKeyDown(81, function (player) {
if (!punchButton) {
punchButton = true;
App.putMobilePunch();
} else {
punchButton = false;
App.putMobilePunch(false);
}
});
putMobilePunchWithIcon
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.
const punchIcon = App.loadSpritesheet("punchIcon.png")
// Activates function when q is pressed
App.addOnKeyDown(81, function (player) {
App.putMobilePunchWithIcon(punchIcon);
});
Appendix
Last updated
Was this helpful?