Struct Array

Tinki3

Special Member
Reaction score
418
I was wondering how to use them, correctly.
I tried, and failed.

I'm trying to manage multiple units that each have a struct assigned to them.
The struct would be attached to a timer that'd be executed every 0.03 seconds.

If I could see an example trigger, that would be great.

Thanks in advance.
 

Terrabull

Veteran Member (Done that)
Reaction score
38
JASS:
struct UnitTimer
    unit Unit
    timer Timer
endstruct

globals
    UnitTimer array UnitsAndTimers
    integer Num_Of_Structs = 0
endglobals

function UseStruct takes nothing returns nothing
    local UnitTimer TempStruct = UnitTimer.create()
    set TempStruct.Unit = bj_lastCreatedUnit
    set TempStruct.Timer = bj_lastCreatedTimer
    set UnitsAndTimers[Num_of_Structs] = TempStruct
    set Num_Of_Structs = Num_Of_Structs + 1
    call TempStruct.destroy()
endfunction


I'm tired, so my variables are not very creative. Please please PLEASE use better variable names than that.
 

Cohadar

master of fugue
Reaction score
209
probably the inner array trick I am using with PUI.
JASS:

struct Data
    private static Data array THIS
endstruct
 

Cohadar

master of fugue
Reaction score
209
Because you could simply use a bunch of arrays outside the struct for the same effect.
 

Terrabull

Veteran Member (Done that)
Reaction score
38
arrays inside a struct should be used to make 2-dimensional (or more) arrays, because that will improve readability of the code. Otherwise, like Cohadar said, there is no reason to use a struct, you essentially have 2 globals with no relation to each other. One main benefit of structs is the ability to tie the data together, which increases ease of use and eases indexing. Your way sort of re-invents the wheel.
 
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