Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   function arguments (https://forums.graalonline.com/forums/showthread.php?t=18906)

btedji 12-14-2001 11:01 PM

function arguments
 
can you pass arguments through functions in graal like this?

funtion Test(this.test){
this.test+=5;
}

Test(5);


this.test would now be worth 10 if it worked

Xaviar 12-14-2001 11:18 PM

Re: function arguments
 
Quote:

Originally posted by btedji
can you pass arguments through functions in graal like this?

funtion Test(this.test){
this.test+=5;
}

Test(5);


this.test would now be worth 10 if it worked

I've tried, and it didn't turn out to well...just put this.test = 5; before the function call

btedji 12-14-2001 11:27 PM

Re: Re: function arguments
 
Quote:

Originally posted by Xaviar


I've tried, and it didn't turn out to well...just put this.test = 5; before the function call

Does that mean it doesn't work??

Xaviar 12-14-2001 11:30 PM

Re: Re: Re: function arguments
 
Quote:

Originally posted by btedji


Does that mean it doesn't work??

I'm sure there is some way to do it...or maybe it was never implemented, but if you screw up a function call, and you test it, it'll say "Error: Expected function() or function(x,y)" or something like that...But, I can't get it to work, so if you can manage, please tell me how...but otherwise, just set the variable to the value you want it, before the function call...You really don't need to pass values, technically, because from a scripts perspective, all variables are global, regardless of where you declare them...

TDO2000 12-14-2001 11:55 PM

at the moment there is no way to use parameters with functions
the () are just used to say, that a function is called...
but functions in gscript accept every variable that was set in the NPC so u can just use this.test if u set it somewhere else in the whole code like

if(playerenters){
this.test=5;
showtext();
}

function showtext() {
message The Number is #v(this.test);
}

LiquidIce00 12-15-2001 04:14 AM

Stefan had said he wasnt gonna do it cuz it had to change a lot of stuff or something

Saga2001 12-15-2001 06:24 AM

well...
 
see you can't do that..
but it doesn't matter...
cause since gscript has a global scope there is no point...
i have always thought there should be global function like
NPC Code:

server/database npc...
global_function functionName() {
do stuff...
}
Other npc on a level...
if (true) {functionName();}


like have a server npc for doing l33t server stuff...
-Past...

btedji 12-17-2001 08:17 PM

Re: well...
 
Quote:

Originally posted by Saga2001
see you can't do that..
but it doesn't matter...
cause since gscript has a global scope there is no point...
i have always thought there should be global function like
NPC Code:

server/database npc...
global_function functionName() {
do stuff...
}
Other npc on a level...
if (true) {functionName();}


like have a server npc for doing l33t server stuff...
-Past...

that would be cool

kyle0654 12-17-2001 10:04 PM

*wants Stefan to add support for arguments in functions*
*has wanted him to since functions were added*

joseyisleet 12-19-2001 03:13 AM

OK, I made this `script` a LONG time ago. It shows how to add stuff for string and stuff.

NPC Code:

// NPC made by Josey Hunt
if (created){
dontblock;
drawoverplayer;
setimg goldball.png;
message Pushups NPC!;
}
if (playertouchsme&&!hasweapon(pushups)) {
toweapons pushups;
setstring pushups,0;
say2 You get 1 gralat for every#b2 push up you do.#bThis is the easiest way#bto make money on Xitami!!#bCommands:Show pushups#bGet money. That's it.;
}
if (weaponfired) {
playerdir=2;
pushups();
i=strtofloat(#s(pushups))+1;
if (i==1000) {setstring pushups,max;
say2 You have done the#bmaximum amount of pushups#ballowed!#bSo cash in and start over!; }
setstring pushups,#v(i);
this.pushups=strtofloat(#s(pushups));
}
if (playerchats&&strequals(#c,show pushups)){
say2 You have done #s(pushups) pushup(s)!;
}
if (playerchats&&strequals(#c,Get money)&&strequals(#w,pushups)){
say2 Here is your money!;
this.rupees=strtofloat(#s(pushups))*2;
playerrupees+=this.rupees;
setstring pushups,0;
}
function pushups(){
disabledefmovement;
playersprite=14;
sleep .1;
playersprite=15;
sleep .1;
playersprite=16;
sleep .1;
playersprite=17;
sleep .1;
playersprite=18;
sleep .1;
playersprite=14;
sleep .1;
playersprite=15;
sleep .1;
playersprite=16;
sleep .1;
playersprite=17;
sleep .1;
playersprite=18;
sleep .1;
playersprite=14;
sleep .1;
playersprite=15;
sleep .1;
playersprite=16;
sleep .1;
playersprite=17;
sleep .1;
playersprite=18;
sleep .1;
playersprite=1;
setani idle,;
enabledefmovement;
}



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

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