Difference between revisions of "HPL3/Scripting/Scripting Guide/Calling Functions and Function Callbacks"
Line 9: | Line 9: | ||
If we want to make the game do something in our script, we need to call a specific function that does what we want. | If we want to make the game do something in our script, we need to call a specific function that does what we want. | ||
− | + | ''Main article: [[HPL3/Scripting/AngelScript Fundamentals/Chapter 6 - Functions|AngelScript - Functions]]'' | |
+ | |||
For example, if we want to make the game do something related to the player, we will type <code>Player_</code>, and then all of the relevant functions for the player can be displayed, with an explanation of what each function does. | For example, if we want to make the game do something related to the player, we will type <code>Player_</code>, and then all of the relevant functions for the player can be displayed, with an explanation of what each function does. |
Latest revision as of 09:52, 16 August 2020
Now that we learned how to write our very first piece of code, we can look into calling functions and function callbacks. FunctionsIf we want to make the game do something in our script, we need to call a specific function that does what we want. Main article: AngelScript - Functions
Player_SetActive(false);in your script file, the player will not be able to be move. This is done through calling the function Player_SetActive . We didn't write any piece of new code, we just used an existing code (function) that does this already.
Function CallbacksFunction 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 an existing 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 PointLight_4 will be visibile or not, depending if the player's flashlight is lit or not. The function OnFlashlightOnOff is called whenever we turn the flashlight on or off. OnFlashlightOnOff is our callback function, which is defined in OnStart .////////////////////////////
// Run first time starting map
void OnStart()
{
Player_SetFlashlightOnOffCallback("OnFlashlightOnOff");
}
//... Somewhere else in the code....
void OnFlashlightOnOff(bool abLit)
{
Light_SetVisible("PointLight_4", abLit);
}
|