Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Functions and junk (https://forums.graalonline.com/forums/showthread.php?t=20802)

Sennema 01-10-2002 06:58 AM

Functions and junk
 
I'm working on a script for something and I'm wondering if it's possible to call a function from within a function.

Something like:

NPC Code:

function test1(){
script stuff;
if(something happens){
test2();
}
return;
}


I'm not sure cause it isn't working to well with what I have. I'm actually testing for a position, and a keydown while at that position.

Goboom 01-10-2002 08:19 AM

Its very possible to use a function inside a function....

Sennema 01-10-2002 08:56 AM

Ok, thanks. Now to figure out what's wrong with it...

WHIPENIE4 01-10-2002 09:15 AM

[screen_name says:]

what does the command 'return' do??

i will probably feel stupid when someone tells me

Er1c 01-10-2002 11:00 AM

Return returns to the part of the script that called the function. In most scripting laungages, when you use return you return information back to the main script, but graal doesn't support that, in graal functions act as if they are just part of the script typed out in a different place.

WHIPENIE4 01-10-2002 08:15 PM

[screen_name says:]

so would this following code be considered good use of the return command

NPC Code:

// NPC made by screen_name
// NPC Name: N/A
// Project: N/A

if (playersays(doit)) {
setplayerprop #c, ;
doingit();
setplayerprop #c, this.counter was equal to #v(this.counter);
}

function doingit() {
this.counter=int(random(0,5));
return;
}



now this will make you say this.counter's value without having to say 'doit' again, right


so, if you are using functions in a timeout, you dont necessarily need returns right?? unless something below is using the new value??

btedji 01-10-2002 08:22 PM

Ive done threefold functions...function in a function which is in another function...it goes as far as you want

Loriel 01-10-2002 09:47 PM

erm no screen_name... if a function is finished, it automatically returns to the main script. It's rather for doing stuff like this...
NPC Code:
if (actionblah) {
do some stuff;
Setani();
do more stuff;
}
function Setani() {
if (!visible) return;
else setcharani blah_idle,;
}


WHIPENIE4 01-10-2002 10:01 PM

[screen_name says:]


okay, i think i understand

Xaviar 01-10-2002 11:16 PM

And don't use playersays =P Use playerchats && strequals(#c,)

WHIPENIE4 01-11-2002 01:23 AM

[screen_name says:]


i usually do, but playersays was faster to type

btedji 01-11-2002 01:56 AM

if for some reason you dont use player chats here is another way

if(strequals(#c,blah)){
setplayerprop #c,;
...commands...
}

WHIPENIE4 01-11-2002 02:13 AM

[screen_name says:]

im not a new scripter, i've been scripting npcs for graal for 2 1/2 years or so

LiquidIce00 01-11-2002 03:19 AM

u can also use break i believe

btedji 01-11-2002 03:47 AM

Quote:

Originally posted by LiquidIce00
u can also use break i believe
break is for loops, it ends the if or while or for loop and continues with the script right after the loop


All times are GMT +2. The time now is 10:51 PM.

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