Difference between revisions of "HPL3/Scripting/Scripting Guide/Calling Functions and Function Callbacks"
Line 13: | Line 13: | ||
Simply put, '''a callback function is just a function which is supposed to be, at some later point, called by some other piece of code, when some event of interest happens.''' It is used a lot when calling game script functions. | Simply put, '''a callback function is just a function which is supposed to be, at some later point, called by some other piece of code, when some event of interest happens.''' It is used a lot when calling game script functions. | ||
− | For example, | + | For example, the function <code>Player_SetFlashlightOnOffCallback</code>, is a function which requires to give a name for a callback function, which will be called when the flashlight is turned on or off. |
− | In other words, when the player | + | In other words, when the player turns the flashlight or on off, a callback function will be called and perform the code inside it. |
{{NavBar|HPL3/Scripting/Hello World|Hello World|HPL3/Scripting/HPL3 Scripting Guide|HPL3 Scripting Guide|HPL3/Scripting/Helper Files|Helper Files}} | {{NavBar|HPL3/Scripting/Hello World|Hello World|HPL3/Scripting/HPL3 Scripting Guide|HPL3 Scripting Guide|HPL3/Scripting/Helper Files|Helper Files}} |
Revision as of 20:36, 10 August 2020
This article is actively undergoing a major edit. The user who added this notice will be listed in its edit history should you wish to contact them. |
Now that we learned how to write our very first piece of code, we can look into calling functions and function callbacks.
If we want to make the game do something in our script, we need to call a specific function that does what we want.
For example, if we want to make the game do something related to the player, we will type Player_
, and then all of the relevant functions for the player can be displayed, with an explanation of what each function does.
Function Callbacks
Function callbacks are used a lot in scripting and they take a big part of our map script file.
Simply put, a callback function is just a function which is supposed to be, at some later point, called by some other piece of code, when some event of interest happens. It is used a lot when calling game script functions.
For example, the function Player_SetFlashlightOnOffCallback
, is a function which requires to give a name for a callback function, which will be called when the flashlight is turned on or off.
In other words, when the player turns the flashlight or on off, a callback function will be called and perform the code inside it.