Difference between revisions of "HPL3/Scripting/Scripting Guide/Calling Functions and Function Callbacks"
Line 1: | Line 1: | ||
{{Hpl3ScriptingGuideMenuBasic}} | {{Hpl3ScriptingGuideMenuBasic}} | ||
{{shortPageTitle}} | {{shortPageTitle}} | ||
+ | {| style="border:0px;" cellspacing="0" | ||
+ | |- valign="top" | ||
+ | | style="padding-right:0.2em" | | ||
Now that we learned how to write our very first piece of code, we can look into calling functions and function callbacks.<br>If we want to make the game do something in our script, we need to call a specific function that does what we want. | Now that we learned how to write our very first piece of code, we can look into calling functions and function callbacks.<br>If we want to make the game do something in our script, we need to call a specific function that does what we want. | ||
Line 29: | Line 32: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[File:Callback-test-hpl3-soma.gif|left|thumb|The above code in action. The flashlight turns the light on / off via callback.]] | [[File:Callback-test-hpl3-soma.gif|left|thumb|The above code in action. The flashlight turns the light on / off via callback.]] | ||
+ | | style="width:0.1%" | | ||
+ | |} | ||
{{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}} | ||
[[Category:HPL3 Scripting]] | [[Category:HPL3 Scripting]] | ||
[[Category:English]] | [[Category:English]] |
Revision as of 21:34, 10 August 2020
Now that we learned how to write our very first piece of code, we can look into calling functions and function callbacks. For example, if we want to make the game do something related to the player, we will type 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 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 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);
}
|