Passing npc array variable to function?

Protos

Core Developers
Messages
236
Points
0
Age
35
IRC Nickname
smoke
Github
smokexyz
Emulator
Is this possible on hercules? I only ask because the wiki states it isn't.

- Edit -

nvm, tested this, doesn't work.

- Edit 2 -

Also, is there a way to check if an getarg(n) exists, if say the variable .@abc is 0 in  callfunc "abc",.@abc; ?

 
Last edited by a moderator:
yes, possible.

Example:

http://pastebin.com/raw.php?i=sgTq0gQR

X6OLlGl.jpg


 
Last edited by a moderator:
Sorry I didn't explain precisely, I'm talking about something along the lines of this for example -

- script test 123,{ OnWhisperGlobal: setarray .@test[0],1,12,123; callfunc "abc",.@test; end;}function script abc { copyarray .@test,getarg(0); dispbottom ""+.@test[1]; return;}

This works, just not for npc variables, like .test

 
Last edited by a moderator:
Sorry I didn't explain precisely, I'm talking about something along the lines of this for example -

- script test 123,{ OnWhisperGlobal: setarray .@test[0],1,12,123; callfunc "abc",.@test; end;}function script abc { copyarray .@test,getarg(0); dispbottom ""+.@test[1]; return;}

This works, just not for npc variables, like .test
example:

Code:
-	script	testnpc	123,{	OnWhisperGlobal:	setarray .test[0],1,12,123;	callfunc "abc";	end;}function	script	abc	{	dispbottom ""+getelementofarray(getvariableofnpc(.test,"testnpc"),1);	return;}
 
Last edited by a moderator:
yeah but then you'd have to use a loop to re-create that array by adding each element, instead of copying from reference. Also what is getarg(0) in that?

 
Last edited by a moderator:
She meant to place .test as arg(0), which would make it pass the info from .test. But if I'm not mistaken, only .test[0].

If you REALLY need to copy an array over to a function for w/e reason, turn it into a temp global array $@test.

You can also use setd/getd to dynamically create these names so they are unique each time you make them, so they don't overlap with one another and cause errors.

 
yeah but then you'd have to use a loop to re-create that array by adding each element, instead of copying from reference. Also what is getarg(0) in that?
you don't need a loop to copy array you can directly access the .test array

get value from  array:

 getelementofarray(getvariableofnpc(.test,"testnpc"), index);

set value to array:

 set( getelementofarray(getvariableofnpc(.test,"testnpc"),index), value);

 
Last edited by a moderator:
Well for the time being i'm using a temporary npc variable .@ , but if I wanted to set it as an NPC variable it's quite inconvenient. 

yeah but then you'd have to use a loop to re-create that array by adding each element, instead of copying from reference. Also what is getarg(0) in that?
you don't need a loop to copy array you can directly access the .test array
get value from  array:

 getelementofarray(getvariableofnpc(.test,"testnpc"), index);

set value to array:

 set( getelementofarray(getvariableofnpc(.test,"testnpc"),index), value);
I know what you're saying, but if I needed to use the entire array conveniently in the function i'd have to recreate it using a loop within the function and assign the elements to a new array. Using that new array would also avoid calling many functions (getelement/variable) repeatedly. It would be nice to be able to pass a direct npc variable reference, I'm not sure what the source on this is yet, I will check it out.

 
Code:
-	script	testnpc	123,{	OnWhisperGlobal:		setarray .test[0],1,12,123;		callfunc "abc";	end;}function	script	abc	{	copyarray .@test, getvariableofnpc(.test,"testnpc"), getarraysize( getvariableofnpc(.test,"testnpc") );	return;}
 
Thank you, that works.

 
Thank you, that works.
You could just pass npc and use copyarray

Code:
-	script	testnpc	123,{	OnWhisperGlobal:		setarray .test[0],1,12,123;		callfunc("abc",.test);	end;}function	script	abc	{        copyarray .@var[0],getarg(0),getarraysize(getarg(0));	    // Use .@var as Array now...	return;}
 
Back
Top