Problem with function returning array

GooS

Azrael
Reaction score
154
Hiya guyses,

So, here's the problem, I've made a function that returns an array, first I didn't even know if it was possible but it went through the compiler so I thought it was fine.

The bad part came now when I attempted to use it, at first I tried to create a local array of the same type and then set that array to the returned one, that gave me the error of not giving an index to the array I'm trying to set to.

JASS:
local integer array int_array
set int_array = FunctionHere(arg)


But I don't want that do I? since I want it become the complete returned array.

So I tried using the function directly in hope that it would work:

JASS:
call FunctionHere(arg)[index]


Did't work either :p so, is there a way?

//==GooS
 

saw792

Is known to say things. That is all.
Reaction score
280
You can't return an array from a function...

Post FunctionHere so we can see what you've done.
 

Romek

Super Moderator
Reaction score
963
You could use a dynamic array or a struct with an array within it.

JASS:
type intarray extends integer array [size] // Instance limit is 8190/size.

function Example takes nothing returns intarray
   local intarray i = intarray.create() // These need to be created manually
   set i[0] = 1
   set i[1] = 2
   return i
endfunction

function AnotherExample takes nothing returns nothing
   local intarray i = Example() // This is created and returned in Example.
   call BJDebugMsg(I2S(i[0])) // Prints 1
   call i.destroy() // Unfortunately, these need to be destroyed manually.
endfunction


Edit: Here's an example which uses a struct with an array within it. This is sometimes preferable if methods, members, or other features are needed.
 

GooS

Azrael
Reaction score
154
You can't return an array from a function...

Post FunctionHere so we can see what you've done.

The only way of returning "an array" would be using a global array, I think.

Ok, thank you guys, guess I'll have to make the array public then :) Forgot that I could do that until I read your post Executor ^^.

//==GooS

EDIT: Romek, I could do that, or just what was said above, which seems so simple that you'd think I
already thought of it, been sitting in front of the trigger window for to long today :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top