Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-16-2008, 12:19 AM
pokeSMOT pokeSMOT is offline
Registered User
Join Date: Jun 2006
Posts: 35
pokeSMOT is on a distinguished road
Newbie Scripter seeks line-by-line breakdown

//#CLIENTSIDE
function onCreated()
Why onCreated() and not just Created()? What does "on" do?
setTimer(0.1);
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;
Does this mean if whatever key '5' represents, pressing the opposite will activate "this.canhit = true;"? And what does that part mean?
setTimer(0.1);
Couldn't the whole function be called?
}
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..
switch (lowercase(key)) {
Is capslock relevant here, or is this for something else?
case "s":
I remember case's from C++, but the next part is what troubles me..
if (this.canhit) {
Is this still asking if while it is true?
player.chat = "s";
So if "this.canhit" was set to true, then it makes the player say "s"? But then how is this.canhit even determinded? By pressing any key other than '5'?
this.canhit = false;
And I'm guessing that absolutely nothing happens if this.canhit is false, cause there's nothing after it except closing brackets
}
break;
And this simply halts the script? no?
}
}

Sorry to whomever takes the time out to read through and answer this post, but I'm really trying to learn this stuff. I find gs2 quite fascinating.
Reply With Quote
  #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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:03 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.