Struct variables array?

Dirac

22710180
Reaction score
147
Hi, i'm creating a spell and i came up with an idea that requieres the variables stored inside a struct to be arrays, but since i added the arrays the spell stops working.
Here's how the struct looks right now
JASS:
    private struct data
        unit array u[8190]
        unit c
        effect array fx[8190]
        real d
    endstruct

Is this an illegal action?
 

Laiev

Hey Listen!!
Reaction score
188
ya, because struct are array, if you use array inside the array, you should limit it like amount you will use... ie;

JASS:

struct data
    unit array myUnit[10]
    effect array myEffect[20]
endstruct


but for every struct used array, you'll reduce the amount of array from the max instances of struct

so
struct 1 will use the array 1, 2, 3, 4, 5... 18, 19, 20 (of 8191)
struct 2 will use the array 21, 22, 23, 24, 25... 38, 39, 40 (of 8191)

and so
 

Laiev

Hey Listen!!
Reaction score
188
the array number of that struct

every struct is an array, and array have limits, in warcraft is 8191, so you can have 8191 structs of that type of struct

so i can do

JASS:
struct data
    integer i
endstruct

function ...
    local data d
    local integer i = 8191

    loop
        set d = data.create()
        set d.i = i
        set i = i - 1
    endloop


if you use array inside struct, the limit of structs will reduce

i suggest you to do something like this:

JASS:
private struct privateData
    unit array u[50]
    effect array e[50]
endstruct

struct data
    privateData pD

    method onInit takes nothing returns nothing
        set pD = privateData.create()
    endmethod
endstruct
 

Dirac

22710180
Reaction score
147
well yea it didnt work when i set the array size to 10 either, and the code, im almost 100% sure wasn't wrong. I tried to do something like this
JASS:
local integer i
call BJDebugMsg("Good So Far")
loop
 exitwhen i == 10
 set i = i + 1
 set d.u<i> = unit
 call BJDebugMsg(&quot;IT WORKS&quot;)
endloop</i>

And the "IT WORKS" msg wasnt being displayed, weird stuff huh?
 
Reaction score
456
What would be really weird is seeing that message displayed. You haven't initialized integer i.
 

WaterKnight

Member
Reaction score
7
To use these arrays, you have to use the standard allocation method btw. Means you have to call .allocate. This assigns the position in the array to the instance.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top