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 09-03-2003, 01:09 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Brief explanations about some new features: (NEW SCRIPT ENGINE)

For those of you who have a good programming experiance, don't bother reading this, this is just a simple thing I decided to type up to prepare those who have no programming experiance for some of the common things in programming languages that will now be in gscript, I aplogize for this being an easy tutorial but I don't really want anyone being confused about these simple things:

1.
Function Params

currently, the only way you can do functions in the current engine is by calling it like

functionname();

and declaring it like

function functionname() {
//script
}

The new engine introduces a popular and great way to 'pass'/declare variables on a function, this is done by using the following:

calling it:

functionname("test",1,a);

declaring it:

function functionname(x,y,z){
//script
}

In the new engine, it gets rid of the need to use setstring to declare a string, you can just go var = "test"; now, so don't be confused by this:

in the example stated before, it is the same as doing in the current engine

x = "test";
y = 1;
z = a;
functionname();

as you can see this is a much more efficent and shorter way to pass/declare variables on a function

2. Declaring a Variable using a Function

what I am talking about, is doing

var = functionname();

Currently you cannot do that, this is an example of using it:

NPC Code:

function functionname(var){
if(var > 10) return(true);
else return(false);
}



The command/function 'return' is used to set the variable calling the function, yes I know right now it is return; you can also use return var; but in the new engine, most of the current commands are converted into functions

3. Switch Statements

these are another way to do else-if statements, some people prefer to use these as they can look neater, example:

NPC Code:

switch(@a) {
case "test":
setplayerprop #c,test;
break;
case 1:
setplayerprop #c,1;
break;
default:
setplayerprop #c,neither 1 or test;
}


this could be considered the equivilent of
NPC Code:

if (a == "test") {
setplayerprop #c,test;
} else if (a == 1) {
setplayerprop #c,1;
} else{
setplayerprop #c, neither 1 or test;
}


personally, I think the switch statement looks neater

the way to start them out is by going
switch (varname) {

}
Please don't ask why I chose to use @, I will explain that on a tutorial explaining some of the new engine's features later.

after that, you can add cases, a case, such as

case "test":
is basically like
if (varname == "test")

if the case is true, it will run all the scripts under it until it reaches the break; command (break(); will work too I believe, I am just using break; for the sake of being less confusing)

also, as you have noticed, I used something that wasn't considered a case, I used
default:

default is basically used when the var isn't equal to any of the cases above it, so it will execute the commands under default: until it finds a break; this is optional so don't feel like you need to include it

4.
do-while loops

these are really similar to while loops, with one difference which I will explain later
NPC Code:

do {
//commands;
} while (condition);


now you may ask,
why not just do
NPC Code:

while (condition) {
//commands;
}


The main difference between while and do-while loops, is that it will execute at least once before it checks the while condition, if the while condition is true, it will continue to do the loop.

5.
More Operators
Post and Pre increment / decrement

post:
var = n++;
this is basically a short way to do
var = n;
n++;

var = ++n;
this is basically a short way or doing
n++;
var = n;

same goes for decrement (--)

Modulus Assignment a %= b
Power Assignment a ^= b

6. Multi Dimention Arrays

An example:

a = b[0][1];
c = b[1][0];
one way you can construct 'b' is by doing

b = {{0,1},{2,3}};
if b was the array in the previous example, a would become 1, c would become 2

there are no limits to how many dimentions you can use, but I really don't see any need to go beyond 3d arrays

7. for loop addition:

I don't really know how to name this, but it is the way java does it, and it is the same as php's

foreach (a as b)

except in gscript, it is
for (b: a)

example:
NPC Code:

a = {5,4,3,2,1};
setarray b,arraylen(a);
i=0;
for(c: a){
b[i] = c;
i++;
}



yes, that was a poor example, but a more practical use would be say...
for(player: allplayers){ ...
which is used on the playerlist script (allplayers can be accessed but not written to clientside)

what it is doing, is taking each instance of the array a, and assigning it as the value b, it can be the equivilent of
NPC Code:

for (i=0; i<arraylen(a); i++){
b = a[i];
}



I may have forgotten some of the new features that are in other coding languages, but if I remember them, I will modify this post to add it, I apologize in advanced for how bad this tutorial was, I admit I kind of lost motivation near the end but I hope it helps comments and critisism is welcome (constructive only please)

EDIT: made the for(var: array) explanation more clear

Last edited by Python523; 09-03-2003 at 03:40 PM..
Reply With Quote
  #2  
Old 09-03-2003, 04:26 AM
protagonist protagonist is offline
Banned
protagonist's Avatar
Join Date: May 2003
Location: CAW
Posts: 5,586
protagonist is on a distinguished road
Send a message via AIM to protagonist Send a message via MSN to protagonist
The new commands are so C-ish.
Reply With Quote
  #3  
Old 09-03-2003, 04:33 AM
Deek2 Deek2 is offline
Registered User
Join Date: May 2002
Location: Springfield, Missouri
Posts: 1,578
Deek2 is on a distinguished road
Neato.
Reply With Quote
  #4  
Old 09-03-2003, 04:54 AM
CheeToS2 CheeToS2 is offline
That Guy
CheeToS2's Avatar
Join Date: Dec 2001
Location: Seattle, WA
Posts: 2,528
CheeToS2 will become famous soon enough
Send a message via AIM to CheeToS2
Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)

Quote:
Originally posted by protagonist
The new commands are so C-ish.
"Quotified for quotability"

Quote:
Originally posted by Python523

except in gscript, it is
for (b: a)

what it is doing, is taking each instance of the array a, and assigning it as the value b, it can be the equivilent of

NPC Code:

for (i=0; i<arraylen(a); i++){
b = a[i];
}

so, you could do something like this?
NPC Code:

if (created){
a = {2,3,5,8};
setarray c,4;
i=0;
for (b: a){
c[i] = b;
setplayerprop #c,Set c[#v(i)] to #v(c[i]);
i++;
}
}
// pointless yeah & more complicated than it needs to be, but just trying to make sure I understand it

__________________


Last edited by CheeToS2; 09-03-2003 at 05:06 AM..
Reply With Quote
  #5  
Old 09-03-2003, 05:25 AM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
Thanks Jagen,that help alot.
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #6  
Old 09-03-2003, 05:41 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
Re: Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)

Quote:
Originally posted by CheeToS2
so, you could do something like this?
NPC Code:

if (created){
a = {2,3,5,8};
setarray c,4;
i=0;
for (b: a){
c[i] = b;
setplayerprop #c,Set c[#v(i)] to #v(c[i]);
i++;
}
}
// pointless yeah & more complicated than it needs to be, but just trying to make sure I understand it

[/B]
I don't think it's a loop, nor does it take the { }'s
just
for (a: b);
that's what I got from it, I haven't seen a few of these types of features before, thanks Jagen
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #7  
Old 09-03-2003, 05:48 AM
Python523 Python523 is offline
Banned
Join Date: Aug 2001
Location: Illinois
Posts: 3,498
Python523 is on a distinguished road
Re: Re: Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)

Quote:
Originally posted by Dach

I don't think it's a loop, nor does it take the { }'s
just
for (a: b);
that's what I got from it, I haven't seen a few of these types of features before, thanks Jagen
it is a loop, as I posted my equivilent to it, the php name for it makes more sense I think, too bad graal doesn't use it

foreach(array as var)
for each element in array, it will set the single element as var, and continue on in the loop until there are no more elements to declare 'var' as

and cheetos, yes your example would work
Reply With Quote
  #8  
Old 09-03-2003, 07:45 PM
Tseng Tseng is offline
Sublime
Tseng's Avatar
Join Date: Jan 2003
Location: California
Posts: 0
Tseng is on a distinguished road
Re: Re: Re: Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)

Quote:
Originally posted by Python523


the php name for it makes more sense I think, too bad graal doesn't use it

foreach(array as var)
for each element in array, it will set the single element as var, and continue on in the loop until there are no more elements to declare 'var' as
I like the Perl way better, it makes more sense, I think.

foreach $var (@somearray) {

Or, if you use strict (which is far superior to normal perl in terms of coding, because it forces you to code more efficiently, and even helps you locate bugs more quickly) and have not declared the variable yet:

foreach my $var (@somearray) {
__________________
Funny Things:
Quote:
Originally posted by Stefan
I didn't ban you, I only played a little bit with my RC.
-----
Reply With Quote
  #9  
Old 09-03-2003, 09:58 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Ruby owns, though.
some_array.each { |some_array_member|
# dostuffhere
}
Reply With Quote
  #10  
Old 09-04-2003, 02:32 AM
Luigi1 Luigi1 is offline
The OtherOther Shaded Leg
Join Date: Jul 2003
Location: In front of a monitor
Posts: 333
Luigi1 is on a distinguished road
I hope there'll be a replacestr. Like the replacestr in PHP. It'd make some things a little easier to do...
__________________
Quote:
Originally Posted by mystic2k
that post did really makes me think how much braincells you have.
*waits for nifty Graal admin person to tell me what happened to vip.graal.net*
Reply With Quote
  #11  
Old 09-04-2003, 03:04 AM
Projectshifter Projectshifter is offline
The David
Projectshifter's Avatar
Join Date: Apr 2002
Location: USA
Posts: 912
Projectshifter is an unknown quantity at this point
Send a message via ICQ to Projectshifter Send a message via AIM to Projectshifter Send a message via MSN to Projectshifter Send a message via Yahoo to Projectshifter
Perhaps I will find some time to write-up a brief doc that explains a few things with obj.function(). The stuff is really nice though, you guys will like it I'm sure =D
Most commands are translated to function, like addtiledef is now addtiledef() and realtext needs to be in quotations.
---Shifter
__________________
Who has time for life these days?
Reply With Quote
  #12  
Old 09-05-2003, 11:21 PM
Knuckles Knuckles is offline
Registered User
Join Date: Sep 2002
Location: New York
Posts: 580
Knuckles is on a distinguished road
Send a message via AIM to Knuckles
Awsome, I always wanted GScript to have the capability of functions being able to return data.
__________________
Knuckles
"They say 60% of the time, it works everytime!"
Reply With Quote
  #13  
Old 09-14-2003, 03:51 PM
Zell2003 Zell2003 is offline
Registered User
Join Date: Sep 2003
Posts: 4
Zell2003 is on a distinguished road
Send a message via ICQ to Zell2003 Send a message via AIM to Zell2003
Why doesn't someone update the NPC Scripting Document.
Attached Files
File Type: zip npcprogramming.zip (78.2 KB, 246 views)
__________________
Im KuJi.
Reply With Quote
  #14  
Old 09-14-2003, 04:11 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura aboutadam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally posted by Zell2003
Why doesn't someone update the NPC Scripting Document.

Becouse there isn't one dedicated tutorial maker among us.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #15  
Old 09-15-2003, 08:05 PM
Chrisz Chrisz is offline
Registered User
Join Date: Oct 2002
Location: Lost...
Posts: 176
Chrisz is on a distinguished road
Send a message via AIM to Chrisz Send a message via Yahoo to Chrisz
Actually, I was making a tutorial, then the new engine starts to emerge c.c... and all the damn GST start to pop up having indepth info via Stefan giving them things. .. Mah. .. I cancelled my old tutorial, and now I await 3.1 for public realease to continue with a new tutorial.

And no, it's not one of them "here's all the commands, now you know them, go away" tutorials. I'm going to do it more of an 'example' tutorial, adding how to's for all the sorts of things that people ask. Though I will do command listing + examples, for reference.
__________________
-Chrisz
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 07:54 AM.


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