I'll try my best to explain it in a way you can understand. Let me know if you still have a question.
Quote:
Originally Posted by pokeSMOT
//#CLIENTSIDE
function onCreated()
Why onCreated() and not just Created()? What does "on" do?
setTimer(0.1);
|
'created' is the name of an event. In GS2, when an event happens, the function onEVENTNAMEHERE() is called (if the function is defined).
Quote:
Originally Posted by pokeSMOT
What is the timer used for? and if it's declared within a function, why not just call the function for later use?
function onTimeout() {
What is the difference between "setTimer" and "onTimeout"?
// or whatever to detect if it's not held down
if (!keydown(5)) this.canhit = true;
|
The difference between setTimer() and onTimeOut() is that using onTimeOut() starts the timeout immediately, while setTimer() lets you define how long you want the script to wait before calling onTimeOut(). In Chompy's example he probably should have used onTimeOut() instead of the first setTimer().
Quote:
Originally Posted by pokeSMOT
Does this mean if whatever key '5' represents, pressing the opposite will activate "this.canhit = true;"?
|
You're very warm. As long key '5' (which is the S key) is not pressed, then this.canhit will be set to true. So, even if nothing is being pushed, this.canhit will be set to true.
Quote:
Originally Posted by pokeSMOT
And what does that part mean?
setTimer(0.1);
Couldn't the whole function be called?
|
In this case, you want a little delay between the next time onTimeOut() is called. You could call onTimeOut() directly, but this will result in it being called too many times too quickly (LAG!).
Quote:
Originally Posted by pokeSMOT
function onKeyPressed(code, key) {
Are "code" and "key" some sort of preset parameters or something? What do those mean? Cause I don't see them defined anywhere..
|
keypressed is an event that passes two parameters when it is called. In GS2, you can give the parameters temporary variables. In this case, Chompy chose to name the variables 'code' and key'. If he didn't name the variables, he would have to access them using params[0] and params[1].
Quote:
Originally Posted by pokeSMOT
switch (lowercase(key)) {
Is capslock relevant here, or is this for something else?
|
You actually do not need to account for caps in this example.
Quote:
Originally Posted by pokeSMOT
And this simply halts the script? no?
|
In switch statements, you need the break at the end of each case to prevent the script from going to the next case. In this example, it isn't really needed as there are no other cases. It's alright to include the break though, so in case you do add to the switch statement later, you won't have to worry about forgetting to add the break.