HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Passing struct data to ForGroups.

07-27-2008, 06:57 AM#1
Vestras
How? If now, we say, I got a struct, and I want the data in a function that I use for ForGroup, then what would I do?
07-27-2008, 07:34 AM#2
Alexander244
Pass the struct instance with a global variable.
07-27-2008, 07:36 AM#3
Vestras
Quote:
Originally Posted by Alexander244
Pass the struct instance with a global variable.

Yeah, but I don't understand those...
07-27-2008, 07:41 AM#4
Alexander244
Collapse JASS:
struct structtype
    //...
endstruct

globals
    structtype TempStruct
endglobals

function TheForGroup takes nothing returns nothing
    //use TempStruct
endfunction

function SomeFunc takes nothing returns nothing
    //...
    set TempStruct = StructInstance
    call ForGroup(g, function TheForGroup)
endfunction
07-27-2008, 07:47 AM#5
Vestras
Quote:
Originally Posted by Alexander244
Collapse JASS:
struct structtype
    //...
endstruct

globals
    structtype TempStruct
endglobals

function TheForGroup takes nothing returns nothing
    //use TempStruct
endfunction

function SomeFunc takes nothing returns nothing
    //...
    set TempStruct = StructInstance
    call ForGroup(g, function TheForGroup)
endfunction

What is the StructInstance? And you don't have to have the global block below the structs.
07-27-2008, 07:56 AM#6
Alexander244
StructInstance is whatever struct instance you're using.
07-27-2008, 08:00 AM#7
Vestras
I must have missed something, or else I'm just too tired, struct instance?
07-27-2008, 08:03 AM#8
Alexander244
You generally work with struct instances, unless you're just using static members?
07-27-2008, 08:22 AM#9
Vestras
But then it won't be MUI?
07-27-2008, 08:24 AM#10
Alexander244
Gnerally it won't be MUI if your not using seperate struct instances to store your data, no.
07-27-2008, 09:03 AM#11
Vestras
And that's the thing I understand how to. It's something with a global integer, right?
07-27-2008, 10:43 AM#12
the-thingy
Quote:
Originally Posted by RoD I
And that's the thing I understand how to. It's something with a global integer, right?
What?

And the struct instance is just
Collapse JASS:
local StructName dat1 = StructName.create () //for example
//Could also be retrieving the struct from something rather than declaring a new one i.e.
local StructName dat2 = GetTimerStructA (GetExpiredTimer ()) //or whatever system you use/handle you want to retrieve from
07-27-2008, 12:24 PM#13
Vexorian
Quote:
Originally Posted by RoD I
But then it won't be MUI?
globals do not automatically make something non-MUI, just like locals/structs won't automatically make something MUI.
07-27-2008, 12:57 PM#14
DioD
You do not need structs for this.

Just pass data into globals and then read this data from ForGroup call.

Nothing can change your data before ForGroup finished (expect event generating actions, soo evoid using same globals everywhere)
07-27-2008, 06:08 PM#15
d07.RiV
You can have a temporary global variable, you set it to whatever struct you are working with and then call the ForGroup. In the callback function you use this global variable. It will be MUI as long as the rest of the code is MUI because this global variable is used only while your trigger is running, and, unless you do something in the callback which might cause the same trigger to activate again (which you shouldn't do), your trigger have only one running instance at a time so it should be all right.