Graal Forums

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

JkWhoSaysNi 03-16-2005 06:23 PM

Functions.
 
I have some questions about the use of functions in gscript:

1. Can you create a function in an npc and call it from another npc? if so, how?

2. Is it possible to pass arguements to functions?

Also, is there any form of inheritance in gscript (ie, basing an npc from another npc).

is it obvious i'm used to OO languages? ;)

Skyld 03-16-2005 08:14 PM

I wasn't entirely sure whether you were talking about Old Gscript or the New Engine, so I'll answer for both.

Quote:

Originally Posted by JkWhoSaysNi
I have some questions about the use of functions in gscript:
1. Can you create a function in an npc and call it from another npc? if so, how?

Gscript: Not that I know of.
Gscript2: Yes, by using public function functionname(params) {
Say you use that in a weapon called "Haha", then you would then call it using Haha.functionname(params);. If your weapon name has spaces, then you would use makevar("Weapon Name").functionname(params);.

Quote:

Originally Posted by JkWhoSaysNi
2. Is it possible to pass arguements to functions?

Gscript: Not that I know of.
Gscript2: Yes, by putting variable names like function functionname(var1, var2) { which will take parameters like functionname(first, second);. In this case, inside the function, var1 and var2 will be set to the given parameters.

Quote:

Originally Posted by JkWhoSaysNi
Also, is there any form of inheritance in gscript (ie, basing an npc from another npc).

I'm not sure what you mean by inheritence, but you can use classes which can be used with putnpc2. This will allow you to write a script and each of these putnpc2'd NPCs will follow it, but they are individual NPCs. Also, you can use join; in a script to include script from a class.

Rick 03-17-2005 05:04 AM

There is no real inheritence in GScript or GScript2.

falco10291029 03-17-2005 05:17 AM

FOr normal gscript, callnpc can be used (maybe not directly, but I'mn sure it can) to call another npc's function, perhaps through something like:

NPC Code:

callnpc index,call,;


and then in the other npc (recieving the command to call the function):
NPC Code:

if (call) funcname();




I used something similar to that in a summoning system.

And Skyld, take that quote of me out of your sig please....

Skyld 03-17-2005 10:09 AM

Quote:

Originally Posted by falco10291029
FOr normal gscript, callnpc can be used (maybe not directly, but I'mn sure it can) to call another npc's function, perhaps through something like:

NPC Code:

callnpc index,call,;


and then in the other npc (recieving the command to call the function):
NPC Code:

if (call) funcname();




I used something similar to that in a summoning system.

You could use triggeraction I suppose. Although, that requires knowing the NPC's location on the board if not a weapon.

Quote:

Originally Posted by falco10291029
And Skyld, take that quote of me out of your sig please....

A'okay. There you go.

JkWhoSaysNi 03-17-2005 04:41 PM

Thanks. I asked about passing variables because when i press test in the level editor it shows it as invalid. I guess it's outdated.

JkWhoSaysNi 03-17-2005 09:28 PM

How do you get the index of the NPC?

Ajira 03-17-2005 10:17 PM

Quote:

Originally Posted by JkWhoSaysNi
How do you get the index of the NPC?

I believe its the var 'id'.

JkWhoSaysNi 03-17-2005 10:28 PM

Thanks. I'll try that. I still cant get parameters for functions to work. Even if i do something as simple as this:
NPC Code:

function finished(what) {
say2 #v(what);
}



It simply wont run. I've tried putting a say2 in with plain text, no variables. It's as if the function never gets called.

Kaimetsu 03-17-2005 10:31 PM

Quote:

Originally Posted by Ajira
I believe its the var 'id'.

Well, ids and indices aren't the same thing, though there're similarities. Still, I can't think of any situation where the id wouldn't suffice.

Quote:

Originally Posted by JkWhoSaysNi
Thanks. I'll try that. I still cant get parameters for functions to work

Dude, you've already been told that it's not a feature of old GScript.

JkWhoSaysNi 03-17-2005 10:43 PM

Erm... how do i know if the server is using gscript or gscript2?

Kaimetsu 03-17-2005 11:09 PM

Quote:

Originally Posted by JkWhoSaysNi
Erm... how do i know if the server is using gscript or gscript2?

Old GScript is a subset of new GScript. Ask the manager if the latter is enabled.

p2p_Sir_Link 03-25-2005 06:47 PM

In the case of Syvlion, it isn't.


All times are GMT +2. The time now is 01:20 AM.

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