| 10-31-2007, 05:03 PM | #1 |
I have a periodical timer, when I change the struct, do I need to attach it to the timer again? JASS:struct Data integer i = 0 endstruct function Example_Execute takes nothing returns nothing local timer t = GetExpiredTimer() local Data d = Data(GetAttachedInt(t, "d")) // ... set d.i = d.i + 1 call AttachInt(t, "d", d) endfunction function Example takes nothing returns nothing local timer t = CreateTimer() local Data d = Data.create() // ... call AttachInt(t, "d", d) call TimerStart(t, 0.04, true, function Example_Execute) // ... endfunction I hope my question is clear. |
| 10-31-2007, 06:33 PM | #2 |
You do not need to reattach it to the timer. |
| 11-01-2007, 10:30 AM | #3 |
Well, that's loud and clear Now I feel like an idiot, I've been reattaching it every time, if only I had known... Thanks for the help |
| 11-01-2007, 02:09 PM | #4 |
That is because a struct variable is just a normal integer, its members are global variable arrays. You change the members but the struct variable isn't, so you don't need to reattach it. vJass uncompiled JASS:struct structdata unit u endstruct function blah takes nothing reutrns nothing local structdata d = structdata.create() //In this case, the struct will be == 1 bec it's the first instance. set d.u = GetTriggerUnit() endfunction vJass compiled JASS:globals //User-defined ... //Generated ... //JASSHelper struct globals constant integer si__structdata=1 integer si__structdata_F=0 integer si__structdata_I=0 integer array si__structdata_V unit array s__structdata_u //Familiar? endglobals ... function blah takes nothing returns nothing local integer c= s__structdata__allocate() set s__structdata_you[c]=GetTriggerUnit() endfunction |
