DeadlySilence Posted April 11, 2013 Posted April 11, 2013 Hello, today I wanted to make a function which returns all IDs of equipped items. The function looks like this: function script getEquip { // get all equipped item IDs .@idx = 0; for (set .@i, 1; .@i < 11; set .@i, .@i + 1) { if (-1 != getequipid(.@i)) { setarray .@items[.@idx], getequipid(.@i); set .@idx, .@idx + 1; } } return .@items; } It's all fine and .@items contains all neccessary IDs. But when I call the function like this: .@a = callfunc("getEquip"); .@a contains only a scalar value (the ID of the first item, I guess), instead of the array with all the IDs. Could someone please tell me how to porperly return an array? Quote
KeyWorld Posted April 11, 2013 Posted April 11, 2013 1) (Euphy ways): function script getEquip { // get all equipped item IDs for (set .@i, 1; .@i < 11; set .@i, .@i + 1) { if (-1 != getequipid(.@i)) { set @items[.@idx], getequipid(.@i); set .@idx, .@idx + 1; } } return @items; } callfunc("getEquip"); // @items2) Your way:function script getEquip { // get all equipped item IDs for (set .@i, 1; .@i < 11; set .@i, .@i + 1) { if (-1 != getequipid(.@i)) { set .@items[.@idx], getequipid(.@i); set .@idx, .@idx + 1; } } return .@items; } copyarray .@items, callfunc("getEquip"), 128;3) By reference:function script getEquip { // get all equipped item IDs for (set .@i, 1; .@i < 11; set .@i, .@i + 1) { if (-1 != getequipid(.@i)) { set getelementofarray( getarg(0), .@idx), getequipid(.@i); set .@idx, .@idx + 1; } } return @items; } callfunc("getEquip", .@items); 4 Quote
Capuche Posted April 11, 2013 Posted April 11, 2013 return .@items; is similar to return .@items[0]; Could someone please tell me how to porperly return an array? A function can only return one value. I suggest to convert your numeric array to string array, return the concatenate array (Implode), then use Explode outside the function to retrieve the values. 3 Quote
Euphy Posted April 11, 2013 Posted April 11, 2013 Alternatively, you can set a temporary character array (@var) instead of scope and clear it afterwards (probably more efficient than string manipulation). 2 Quote
DeadlySilence Posted April 20, 2013 Author Posted April 20, 2013 Thank you for your help, I got it working now Quote
Question
DeadlySilence
Hello,
today I wanted to make a function which returns all IDs of equipped items. The function looks like this:
It's all fine and .@items contains all neccessary IDs.
But when I call the function like this:
.@a contains only a scalar value (the ID of the first item, I guess), instead of the array with all the IDs.
Could someone please tell me how to porperly return an array?
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.