HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Enumeration with callback function, arguments possible?

01-26-2008, 05:01 PM#1
Jitse
Hi ho

I think this question is quite obvious, and probably asked several times before. But is it possible, when you set up an enumeration, say ForForce, to pass a local variable to the callback function?

Collapse JASS:
native ForForce takes force whichForce, code callback returns nothing

I'm afraid I already know the answer to this question, but I've still got a spark of hope somewhere very deep in my obscure caverns of desperation that a messiah will come to enlighten me.

Thanks in advance
01-26-2008, 05:18 PM#2
Ammorth
Use a global to transfer the local variable.
01-26-2008, 07:08 PM#3
Jitse
Hooray, wasting a complete global for one time I want to initialize a trigger... I know how to do it without passing, and I even don't really have to use a callback function, I can just make it a loop, but it's just nicer with a nice ForForce enumeration. Isn't there any way to pass a local variable to another function in callback form?
01-27-2008, 09:28 AM#4
Troll-Brain
No use a global
01-27-2008, 02:22 PM#6
Rising_Dusk
ForGroup() enumeration does not permit passing locals. You don't have to 'waste a global' or even declare a new one. I always use one of the random BJ globals built into every WC3 map. If you need to pass a unit, use bj_ghoul[1] or something. Just open up the BJ and check it out, there's a whole list.
01-27-2008, 06:23 PM#7
Jitse
Hehe good idea. But it's a trigger I want to pass, and I don't see any trigger variables or arrays in the globals list of BJ that are healthy to mess with. Anyway, I'll just use the default global trigger that's created but not used because I use scopes and local triggers. I'll take your idea in mind for next time. :)

Thanks for all the replies. (+ rep for the only person that actually gave an answer longer than one phrase)
01-27-2008, 06:59 PM#8
moyack
I suggest to use this BJ variable: bj_destInRegionDiesTrig
01-27-2008, 09:19 PM#9
Vexorian
Just make the global.

Or how about stopping to use ForGroup? I doubt there is any legit use for it.
01-28-2008, 12:13 AM#10
xombie
If you really don't want to declare a global, then create a trigger-page called Trig and you will now have access to the variable: gg_trg_Trig
01-28-2008, 11:01 AM#11
Troll-Brain
Quote:
Originally Posted by Vexorian
Just make the global.

Or how about stopping to use ForGroup? I doubt there is any legit use for it.

A ForGroup is faster than create an other group and remove/add the units, no ?
(if you don't need to filter the units in this group)
01-28-2008, 06:30 PM#12
Jitse
Quote:
Originally Posted by Vexorian
Just make the global.

Or how about stopping to use ForGroup? I doubt there is any legit use for it.
It's ForForce, not ForGroup. And a force is a group of players, which you obviously know. I store all active players in a force at the initialization of my TD. So I don't have to go through all players and filter the playing ones every time again I have to initialize something (such as a trigger). Now you're saying: who cares if a trigger also checks non-playing players. But you've also got the creep computers, which are more than one, and the number can still change during development. I just want it all to be decently dynamic, as all scripting and programming code should be. Imagine I suddenly notice I need a third creep computer (instead of two), then I'd have to go find all loops that enumerate the players and decrement the max integer of the loop with one.

Quote:
Originally Posted by xombie
If you really don't want to declare a global, then create a trigger-page called Trig and you will now have access to the variable: gg_trg_Trig
Ahum... What's the difference between that, or declaring a global yourself? There is none.

As you can read in my previous post, this topic is answered already.
01-28-2008, 07:53 PM#13
Vexorian
Quote:
Originally Posted by Troll-Brain
A ForGroup is faster than create an other group and remove/add the units, no ?
(if you don't need to filter the units in this group)
But if you actually used a ForGroup for group objects that are permanent, it would mean... that you are actually using permanent groups and that's worse.

Quote:
It's ForForce, not ForGroup
All right, I didn't notice. But ForForce is even more deserving of the pointless denomination than ForGroup is.

Collapse JASS:
 local integer i=0
    loop
           exitwhen i>=16
           if (PlayerInForceWhateverThisNativeIsCalled( Player(i) , myForce) ) then
                //do something.
           endif
           set i=i+1
    endloop
01-28-2008, 08:24 PM#14
TaintedReality
You could also just have a global boolean array, set it to true if they're playing, false if not, then check that.
01-28-2008, 08:26 PM#15
Jitse
Quote:
Originally Posted by Vexorian
Collapse JASS:
 local integer i=0
    loop
           exitwhen i>=16
           if (PlayerInForceWhateverThisNativeIsCalled( Player(i) , myForce) ) then
                //do something.
           endif
           set i=i+1
    endloop


You've got a point there. I'll just use that in the future. I actually even shouldn't be using a force. If I'm using a force that's just being initialized at the beginning of the map, as I am now, I could just do:

Collapse JASS:
    local integer i=0
    loop
           exitwhen i>=16
           if (ConditionsForBeingInForceApply(Player(i))) then
                // do something
           endif
           set i = i + 1
    endloop

Which wouldn't even need a force global.

Whatever, I'm just going to keep it as I have it now, and change it later. I've not been developing my map very attentively the last few days, mainly because of my exams, which actually only lets me reply to some topics on the forum, and nothing more. :p

Alright, topic answered, thanks for all the replies. :)