• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Solved] Code Help please!

Status
Not open for further replies.
Level 6
Joined
May 15, 2008
Messages
147
OK I've got the following issue:
When using ForGroup() function, I set the group and code parameter however, I cannot add the parameter to the code inside the brackets and I need it since I'm using hashtable to save data and transfer the amount of damage and damager unit into that separate function that deal damage let's call it Example_Damage, it should take unit and real parameters.
Here is the closer explanation:

JASS:
call ForGroup(ExampleGroup, function Example_Damage)
//Thats the right function, however I need something like this

call ForGroup(ExampleGroup, function Example_Damage(u1, damage))
//since I'm using hashtable to save the data for spell like u1 which is
//damager and "damage" which is real amount of damage.
//The problem is that I'm using the expiring id of a timer as a parentkey
//for hashtable storage and I can get it only in the Example_Action func
//which sort of represents the function which does the effects for the spell, 
//or not?
//Above function gives error when saving map becouse of the () after
//the Example_Damage code callback

Can I maybe also use:
JASS:
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
within the Example_Damage functionto get the id of handle (which is the key for the hashtable data) and use it to get u1 the damager and damage real?
 
You can not pass parameters in code callback for ForGroup() since it's function of type: takes nothing returns nothing. And you can not change that ;/

Although globals and hashtables can help you with dealing with such issue.

For egzample save the damage and unit on child key (hashtable usage) of every unit in group to later refer back to it via GetHadnleId(GetEnumUnit()) and load the data.
Unit Indexer/globals are easier to achieve. Via unit indexer to can: set damage[GetUnitUserData(unit)]. And with simple globals just set it to given value and refer to it within each group instance.
 
If you want to keep your local variables you can use FirstOfGroup
loops you'll end up getting better performance the more data you
need to attach.

For timers, it can get ugly. There seems to be a limitless number
of different timer systems out there and not one of them is terribly
intuitive. I prefer a periodic timer that iterates through a list or a
unit group, using a "remaining time" variable to manage various
periodic events.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Just use a global variable to pass data, there are enough bj globals if you don't want to create a new one.
 
Level 16
Joined
Aug 7, 2009
Messages
1,406
Well, I suggest global variables.

However the way I'm doing is Set/GetGroupData. I've written my own GroupTools library, and since I'm working with SpellStruct and different modules, I can easily retrieve the ForGroup group and its data. I simply attach the struct to the group which contains the damage, the caster, the slow/haste/blind factors, etc.

I can send you that little snippet if you want.
 
Level 6
Joined
May 15, 2008
Messages
147
OK thank you people I got it sound and clear ^^

@Luorax Thank you for the library it would be awesome, but I'm not sure if that'll help much I'm still doing the basic thingies and out of 10 codes 1 I make works, since I lack so many sintaxes and finesses, I wanna learn a little more before going on to libraries structs and etc. For exapmle this spell, about the original queston was gives me a pain in the ... the whole morning and good time of the afternoon but I'm not gonna let it win :grin:
 
Status
Not open for further replies.
Top