HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Local variable inside native function

08-19-2004, 12:07 AM#1
cresonic
This may be misplaced since it involves JASS, but the description of the JASSvault kinda suggests that it is not for questions. Anyone who can do so, please move it if it's misplaced...

I am having a tower cast slow on every packhorse in a range of 500 every 5 seconds if the towers custom value = 1...

Since i do a "Pick every unit in unitgroup" inside another one, and i need both units for the final "issue order targeting a unit" I am using local variables...

Since the whole local variables thing is a mess when you try to GUI it, I converted my function and turned all the functions involving the local variable into one...

But when I try to turn on the trigger WE just slams the code in my face and says it wants a name on line 33, which says this:
Code:
call ForGroupBJ( GetUnitsInRangeOfLocMatching(500.00, GetUnitLoc(GetEnumUnit()), condition( GetUnitTypeId(GetFilterUnit()) == 'h000' ), call IssueTargetOrderBJ( Tower , "slow", GetEnumUnit()) )

Long line I know... but as far as I know JASS does not tolerate linebreaks before end of sentence (they should have gone with the good old ";"-seperator :god_help_us: )

I am thinking its something with that variable i feed "IssueTargetOrderBJ()" with.... but I cant figure it out.

The entire trigger-code:
Code:
function GoThroughTowers takes nothing returns nothing
    local unit Tower
    call PingMinimapLocForForce( GetPlayersAll(), GetUnitLoc(GetEnumUnit()), 1 )
    if ( GetUnitUserData(GetEnumUnit()) == 1 ) then
        call DisplayTextToForce( GetPlayersAll(), "DEBUG: autorerouting" )
        set Tower = GetEnumUnit()
        call ForGroupBJ( GetUnitsInRangeOfLocMatching(500.00, GetUnitLoc(GetEnumUnit()), condition( GetUnitTypeId(GetFilterUnit()) == 'h000' ), call IssueTargetOrderBJ( Tower , "slow", GetEnumUnit()) )
    endif
endfunction

function Trig_auto_reroute_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsOfTypeIdAll('h002'), function GoThroughTowers )
endfunction

//===========================================================================
function InitTrig_auto_reroute takes nothing returns nothing
    set gg_trg_auto_reroute = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_auto_reroute, 5.00 )
    call TriggerAddAction( gg_trg_auto_reroute, function Trig_auto_reroute_Actions )
endfunction

Any help is GREATLY appreciated...
08-19-2004, 03:43 AM#2
GeneralStonewal
You forgot to close one of the parenthesis I believe.
08-19-2004, 03:53 AM#3
GeneralStonewal
call ForGroupBJ( GetUnitsInRangeOfLocMatching(500.00, GetUnitLoc(GetEnumUnit()), condition( GetUnitTypeId(GetFilterUnit()) == 'h000' ), call IssueTargetOrderBJ( Tower , "slow", GetEnumUnit()) )

I believe that second call is your problem.
08-19-2004, 07:32 AM#4
cresonic
I still cant get it to work.... its like it wont accept my variable, so im doing a clumsy global one. (hate global vars :P )

But thanks anyways : )
08-19-2004, 12:03 PM#5
weaaddar
A) Your leaking a unit group.
B) You must point the code at a function which parameters are takes nothing returns nothing
C) The function must be passed as a pointer (i.e. function MYFunc).
08-19-2004, 11:00 PM#6
Cubasis
I reccomend you to use a technique to iterate through groups without using ForGroup, where you can then use your local variables. It works like this:

You first need a unit local variable and perhaps a temporary group object if the group you're working with is a permanent (if you don't want to destroy it).

So let's say we're working with our hero group and thus we don't want to destroy it, we'd have these declerations:

Code:
local unit u
local group g = CreateGroup() //Optional
call GroupAddGroup( HeroGroup, g ) //Optional

Then we start a loop. Here's a example framework for this kind of loop.

Code:
loop
   set u = FirstOfGroup(g)
   exitwhen u == null
   // u is here the "GetEnumUnit" and you can mess with it all you want except perhaps removing it (as that may mess up the loop a lil).
   call GroupRemoveUnit(g, u)
endloop

~Cubasis