Difference between revisions of "HPL3/Scripting/Scripting Guide/Calling Functions and Function Callbacks"

From Frictional Wiki
Jump to navigation Jump to search
(Created page with "{{ShortPageTitle}} 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 s...")
 
Line 1: Line 1:
{{ShortPageTitle}}
+
{{Hpl3ScriptingGuideMenuBasic}}
 +
{{shortPageTitle}}
 +
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.
+
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.  
  
If we want to make the game do something in our script, we need to call a specific function that does what we want.
+
== Function Callbacks ==
  
Luckily, it is quite simple to do.
+
Function callbacks are used a lot in scripting and they take a big part of our map script file.
  
For example, if we want to make the game do something related to the player, we need to start typing Player_ , and all of the relevant functions for the player can be displayed, with an explanation of what each function does.  
+
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.
  
As for function callbacks, they are used a lot in scripting, and they take a big part of our map script file.
+
For example, let’s look at <code>Player_StartLookAt</code>, a function which have an optional parameter, as you can see, we have the option for it to call another function when the lookat ends.
  
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.
+
In other words, when the player has reached the destination to look at, a callback function will be called and perform the code inside it.
  
For example, let’s look at Player_StartLookAt, as you can see, we have the option for it to call another function when the lookat ends.
+
{{NavBar|HPL3/Scripting/Hello World|Hello World|HPL3/Scripting/HPL3 Scripting Guide|HPL3 Scripting Guide|HPL3/Scripting/Helper Files|Helper Files}}
  
In other words, when the player has reached the destination to look at, a callback function will be called and perform the code inside it.
+
[[Category:HPL3 Scripting]]
 +
[[Category:English]]

Revision as of 15:57, 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.
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, let’s look at Player_StartLookAt, a function which have an optional parameter, as you can see, we have the option for it to call another function when the lookat ends.

In other words, when the player has reached the destination to look at, a callback function will be called and perform the code inside it.