HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trying to learn how to write JASS properly

05-07-2005, 02:17 PM#1
Anitarf
Ok, because of the incredibly annoying bugged cast event responses, I decided to use local variables in a trigger. So far, it has gone all right, I translated all the actions that had to use the local variables to JASS and copied them into my GUI trigger as custom script lines. So far so good.

However, I at some point came to the problem that I transformed a "pick all units in unit group" function to JASS and it turned into a entire function and a line that calls it. Seeing no way around it, I gave up on trying to have the whole trigger in, well, one trigger, and so I copied the function to the map header and the line that calls it to my trigger.

Then I suddenly realized (dooh, I got a bunch of compile errors) I was using my local variables in that function, which was clearly wrong because the function is a separate thread. So, I changed the function to accept some parameters and used those in the function, and it no longer gives me any compile errors.

However, I can't test yet if this bundle of JASS I mucked up actually works, because I have one more compile error, which I can't figure how to get rid of. It's in the line that calls this function, and I can't figure out how to write it properly, it says "Expected: ' ". So, here it is, first the now apparently unproblematic function:
Code:
function DivineRetributionDamage takes integer HeroIndex, integer BaseDamage returns nothing
    call AddSpecialEffectTargetUnitBJ( "origin", GetEnumUnit(), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" )
    call DestroyEffectBJ( GetLastCreatedEffectBJ() )
    call UnitDamageTargetBJ( udg_GPHero[HeroIndex], GetEnumUnit(), I2R(( BaseDamage / 2 )), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL )
endfunction
And now the problematic line of code (TempInt and AnotherOneJustBecauseICan are local integers):
Code:
call ForGroupBJ( udg_TempCSUnitGroup[AnotherOneJustBecauseICan], function DivineRetributionDamage( AnotherOneJustBecauseICan, TempInt ) )
Ok, so what did I do completely wrong?
05-07-2005, 02:49 PM#2
Vexorian
Blizzard is doing it wrong, you can't pass arguments to enumerating functions.

You will have to use temporary a global variable to save the value of the local

Or you can use something like this:

Code:
   local unit p
   local group g=#the group for the enum#
    loop
          set p=FirstOfGroup(g)
          exitwhen (p==null)
          call GroupRemoveUnit(g,p)
          //Do stuff with p as if it was the picked unit
    endloop
05-07-2005, 03:26 PM#3
Anitarf
Quote:
Originally Posted by Lord Vexorian
Blizzard is doing it wrong, you can't pass arguments to enumerating functions.

You will have to use temporary a global variable to save the value of the local

Or you can use something like this:

Code:
   local unit p
   local group g=#the group for the enum#
    loop
          set p=FirstOfGroup(g)
          exitwhen (p==null)
          call GroupRemoveUnit(g,p)
          //Do stuff with p as if it was the picked unit
    endloop
Yes, I was thinking of doing it this way even if the current way could be done. I was going to use random unit from group, but if I use FirstOfGroup, do I even need p, can't I just do all the actions with the FirstOfGroup(g) as the argument and use the GroupRemoveUnit at the end of the loop?
05-08-2005, 10:42 PM#4
Vexorian
Not using p would only mean a lost of execution time and the risk of FirstOfGroup giving other value.
05-09-2005, 01:39 AM#5
Anitarf
That's a risk? I thought FirstOfGroup was, well, first of a group, always the same unless the group changes, which it doesn't untill you remove the unit from it, but by then you already want it to pick a differnet unit the next time the loop runs.

Well, not to be arguing or anything, I used a unit anyway, just asking myself some questions so I'm not just a dumb follower. :)
05-09-2005, 05:47 PM#6
Vexorian
FirstOfGroup could change accidentally if one of the pieces of code you have inside the loop, make a trigger with an action run and if the action does something with a unit inside the group.

Could happen.

But most likelly blizzard always make weird things, really weird things and FirstOfGroup not always giving the same value could happen.