1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] Code Help please!

Discussion in 'Triggers & Scripts' started by Darkwing, Sep 2, 2011.

  1. Darkwing

    Darkwing

    Joined:
    May 15, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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:

    Code (vJASS):

    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:
    Code (vJASS):
        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?
     
  2. Bannar

    Bannar

    Joined:
    Mar 19, 2008
    Messages:
    3,087
    Resources:
    20
    Spells:
    5
    Tutorials:
    1
    JASS:
    14
    Resources:
    20
    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.
     
  3. Adiktuz

    Adiktuz

    Joined:
    Oct 16, 2008
    Messages:
    9,674
    Resources:
    23
    Models:
    2
    Packs:
    1
    Maps:
    1
    Spells:
    16
    Tutorials:
    1
    JASS:
    2
    Resources:
    23
    yeah, sadly you need to find another way to pass arguments to the function that the ForGroup will run...
     
  4. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,059
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    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.
     
  5. Ceday

    Ceday

    Joined:
    Feb 22, 2010
    Messages:
    1,098
    Resources:
    0
    Resources:
    0
    Just use a global variable to pass data, there are enough bj globals if you don't want to create a new one.
     
  6. Luorax

    Luorax

    Joined:
    Aug 7, 2009
    Messages:
    1,301
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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.
     
  7. Darkwing

    Darkwing

    Joined:
    May 15, 2008
    Messages:
    150
    Resources:
    1
    Maps:
    1
    Resources:
    1
    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: