Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Brief explanations about some new features: (https://forums.graalonline.com/forums/showthread.php?t=47663)

Python523 09-03-2003 01:09 AM

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

protagonist 09-03-2003 04:26 AM

The new commands are so C-ish.

Deek2 09-03-2003 04:33 AM

Neato.

CheeToS2 09-03-2003 04:54 AM

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


osrs 09-03-2003 05:25 AM

Thanks Jagen,that help alot.

Dach 09-03-2003 05:41 AM

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 ;)

Python523 09-03-2003 05:48 AM

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

Tseng 09-03-2003 07:45 PM

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) {

Loriel 09-03-2003 09:58 PM

Ruby owns, though.
some_array.each { |some_array_member|
# dostuffhere
}

Luigi1 09-04-2003 02:32 AM

I hope there'll be a replacestr. Like the replacestr in PHP. It'd make some things a little easier to do...

Projectshifter 09-04-2003 03:04 AM

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

Knuckles 09-05-2003 11:21 PM

Awsome, I always wanted GScript to have the capability of functions being able to return data.

Zell2003 09-14-2003 03:51 PM

1 Attachment(s)
Why doesn't someone update the NPC Scripting Document.

adam 09-14-2003 04:11 PM

Quote:

Originally posted by Zell2003
Why doesn't someone update the NPC Scripting Document.

Becouse there isn't one dedicated tutorial maker among us.

Chrisz 09-15-2003 08:05 PM

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.

GoZelda 09-17-2003 05:48 PM

Re: Brief explanations about some new features: (NEW SCRIPT ENGINE)
 
Quote:

Originally posted by Python523
The new features
Mh, i really need to read the functions stuff more careful because variable passing is a bit unclear to me. Or i think XD does it work like this:

NPC Code:

if (playerenters){
a=10;
b=10;
c=7;
multiply_em(a,b,c);
}
function multiply_em(d,e,f){
g=d*e;
h=g*f;
message #v(h);
}
//very simple, lol.


i should get as outcome (10*10)*7 (=700), right...?

Also, can we do this:

Is there a way to use a "message" that uses a function? I mean like this (Javscript):
NPC Code:

alert("You have" + getcash(client.taxreturn,client.salary) "dollars!);
function getcash(x,y){
this.cash=x*y;
return this.cash;
}


GoZelda 09-17-2003 05:51 PM

Quote:

Originally posted by adam



Becouse there isn't one dedicated tutorial maker among us.

*ahem ahem* *points at self* I made a new commands.rtf ... This sounds fun XD Sorry for double post B.T.W.
Also, tutorials and stuff:
http://www.freewebs.com/graaleditor

Admins 01-31-2004 11:45 PM

There is more in the new scripting engine though:

1. Compatible to old scripts
2. Object-oriented with variant variables
3. Easier access to variables
4. Powerful GUI
5. Additional functions for catching and invoking events
6. Loading and saving files

And more...

adam 01-31-2004 11:51 PM

Ok, thats' just mean. Telling us about all the things we cannot have. ;)

And clear your pm box already. hehe.

Termina_Owner 02-01-2004 12:21 AM

Holy ****! Object-Oriented? That's just awesome!

I haven't been using object-oriented things for a long time, but they were awesome... Erm, for you who don't know... How can I explain:

Object Oriented is something that you can somewhat have a whole new ****load of arrays in a variable, along with it's own function set and all!

As in PHP:
NPC Code:

class dog{
var health;
function bark(){
setcharprop #c,Woof Woof!;
}
function whimper(){
setcharprop #c,Err... Err...!;
}
function attack(otherdog){
otherdog->hurt(5);
}
function hurt(damage){
health = health - 5;
if (health <= 0)
setcharprop #c, Arg... I'm dead;
}
}
if (playerenters){
dog = new dog(10);
healthydog = new dog(100);
healthydog-> bark();
dog-> whimper();
healthydog-> attack(dog);
dog-> attack(healthydog);
healthydog-> attack(dog);
}



Erm... Yea, that seems right... :) It's having a whole basin of function into a variable... It's basically like classes, but much easier to control... Perhaps in a hat shop, you could have One NPC having control of all the hats there, instead of all the hats having itself as a class...

Say, could we do:
NPC Code:

if (playerenters){
npcs[index].OBJECT-> Function(data1,data2);
}


?
It would be awesome if we could... Anyhow! When is the new engine planned to be released? You got me anxious (Well, more then I actually am).

ZeLpH_MyStiK 02-01-2004 04:42 AM

Wow old gscript was so much easier. I think i'll just stick to the old gscript unless certain new features don't work the old way.

Python523 02-01-2004 05:12 AM

Quote:

Originally posted by Termina_Owner

<stuff>

It isn't really anything like php's version of OOP

Thought 02-01-2004 05:40 AM

Function parameters -- can you pass by reference?

xManiamaNx 02-01-2004 07:06 AM

Quote:

Originally posted by ZeLpH_MyStiK
Wow old gscript was so much easier. I think i'll just stick to the old gscript unless certain new features don't work the old way.
I dont see anything harder about the new engine. I just see many new features that will make it better than the old one.

GoZelda 02-01-2004 05:14 PM

The new engine isn't there to make it harder, dudes.

ZeLpH_MyStiK 02-01-2004 07:50 PM

Quote:

Originally posted by xManiamaNx


I dont see anything harder about the new engine. I just see many new features that will make it better than the old one.

Look at the syntax for the for loops, it's more confusing.
(Sounds like Python: for i in range(1,5):)

Admins 02-02-2004 01:23 PM

Quote:

Originally posted by Termina_Owner

As in PHP:
NPC Code:

if (playerenters){
dog = new dog(10);
healthydog = new dog(100);
healthydog-> bark();
dog-> whimper();
}



It would be awesome if we could... Anyhow! When is the new engine planned to be released? You got me anxious (Well, more then I actually am).

You can call functions of other npcs if they are declared public (public function ...).
The class system is the same like the old Graal class system, except that you can join and leave at any time you want. You can do things like

myvar = "test";
myvar.join("dogs");
myvar.whimper();

which is then using the dogs class

GoZelda 02-02-2004 05:54 PM

Quote:

Originally posted by Stefan


You can call functions of other npcs if they are declared public (public function ...).

That's pretty cool :eek: This could be an alternative for a lot of sets, triggeractions etc...h


All times are GMT +2. The time now is 07:49 PM.

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