Thread: keydown2
View Single Post
  #2  
Old 02-16-2008, 03:33 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
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 View Post
//#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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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 View Post
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.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.

Last edited by napo_p2p; 02-16-2008 at 08:23 AM..
Reply With Quote