Difference between revisions of "HPL3/Scripting/Scripting Guide/The OnAction method"
Line 23: | Line 23: | ||
[[HPL3/SOMA/Scripting/iKeyboard|iKeyboard]] | [[HPL3/SOMA/Scripting/iKeyboard|iKeyboard]] | ||
− | {{NavBar|HPL3/Scripting/ | + | {{NavBar|HPL3/Scripting/Helper Files|Helper Files|HPL3/Scripting/HPL3 Scripting Guide|HPL3 Scripting Guide|HPL3/Scripting/The Update method|The Update method}} |
[[Category:HPL3 Scripting]] | [[Category:HPL3 Scripting]] | ||
[[Category:English]] | [[Category:English]] |
Revision as of 22:30, 11 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. |
In the next two chapters we will look over useful functions that exist in every map script file.
OnAction
This method gets called when a key on the keyboard is pressed. It detects the keyboard input, and it is mostly used for testing parts of our script. It can be very useful to us when we want to test something quickly. Below is the default code in a map script file for OnAction
:
As you can see, the function has two arguments: alAction and abPressed. alAction is an integer which represents the key code of the current key has been pressed, and abPressed is a boolean which checks if the key is currently pressed. After that, we check if the current button is pressed or not, because we want to execute our code only when our button is pressed, so if the key isn’t pressed, we stop the execution of this method, which is achieved by typing return.
And now we have a condition that checks which key we have pressed. We can search for keys by typing eAction_ and we will see a list of all of the available keys, which is pretty much every key on the keyboard. eAction_Test0 to eAction_Test9 are the number keys on the keyboard, so if we press 0 on our keyboard, the code inside the eAction_Test0 condition will be executed.
Let’s see an example.
I have a map with a boxlight. When I press 0, the boxlight will turn red, and when I press 1, the boxlight will turn blue.
- shows an example*
Of course, we can do much more complicated things with this method, we can test sequences, events, and pretty much everything concerning our map script.