Jump to content
  • 0

send array through callfunc, it is possible?


Question

Posted (edited)

Hi, Im trying to send an array using callfunc but I only got the first value. I tried several ways like

- using functions inside same npc

- getting the array value from inside the function with getvariableofnpc

my example:

OnInit:
setarray .items[0],1,2,3,4,5;

...
  
callfunc("MyFunction",.items);

...
  
function	script	MyFunction	{
  
  setarray .@itemsTemp, getarg(0);
  
  for(.@i = 0 ; .@i < getarraysize(.@itemsTemp) ; .@i++)
  {
   	mes "Item: " + .@itemsTemp[.@i];
  }
  
  return;
}

...
  
Output:

Item: 1
  
  
forcing "for" with a fixed number will Output:

Item: 1
Item: null
Item: null
Item: null

 

It is possible? Or should I rethink my NPC behaviour? THanks

Edited by Kota

2 answers to this question

Recommended Posts

  • 0
Posted

you can do it these ways

function	script	MyFunction1	{
	.@size = getarraysize(getarg(0));
	for (.@i = 0; .@i < .@size; .@i++)	
		mes "array_1["+.@i+"] = "+getelementofarray(getarg(0), .@i);
	return;
}
function	script	MyFunction2	{
	.@size = getarraysize(getarg(0));
	copyarray .@new_array, getarg(0), .@size;
	for (.@i = 0; .@i < .@size; .@i++)	
		mes "array_2["+.@i+"] = "+.@new_array[.@i];
	return;
}

 

Sample

-	script	sample	-1,{
	OnInit:
		sleep 3000;
		setarray .items_1,1,2,3,4,5;
		callfunc("MyFunction1",.items_1);
		
		setarray .items_2,10,20,30,40,50,60,70;
		callfunc("MyFunction2",.items_2);
		
		end;
}

Output

[Debug]: array_1[0] = 1
[Debug]: array_1[1] = 2
[Debug]: array_1[2] = 3
[Debug]: array_1[3] = 4
[Debug]: array_1[4] = 5

[Debug]: array_2[0] = 10
[Debug]: array_2[1] = 20
[Debug]: array_2[2] = 30
[Debug]: array_2[3] = 40
[Debug]: array_2[4] = 50
[Debug]: array_2[5] = 60
[Debug]: array_2[6] = 70

 

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...