Jump to content
  • 0
Sephus

Passing npc array variable to function?

Question

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

Edited by Smokexyz

Share this post


Link to post
Share on other sites

10 answers to this question

Recommended Posts

  • 0
-	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;}

Share this post


Link to post
Share on other sites
  • 0

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

Edited by Smokexyz

Share this post


Link to post
Share on other sites
  • 0

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:

-	script	testnpc	123,{	OnWhisperGlobal:	setarray .test[0],1,12,123;	callfunc "abc";	end;}function	script	abc	{	dispbottom ""+getelementofarray(getvariableofnpc(.test,"testnpc"),1);	return;}
Edited by Angelmelody

Share this post


Link to post
Share on other sites
  • 0

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?

Edited by Smokexyz

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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

 

 

Edited by Angelmelody

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

Thank you, that works.

You could just pass npc and use copyarray

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.