HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

locals not working

04-18-2004, 03:00 AM#1
-={tWiStÄr}=-
im making a trigger and i want to change all of its variables to local instead of globals, so all i do is define the locals and then get rid of the udg_ in front of all the instances of the trigger, but it doesnt work. and it works fine when theyre globals.
04-18-2004, 04:06 AM#2
The Gearhead
local [type] [name]

Make sure you define it, you can do this by:

local [type] [name] = [definition by default]

Is this what you are looking for?
04-18-2004, 04:09 AM#3
-={tWiStÄr}=-
huh... no i did
heres exactly what i have
local location Frozenfeetpoint = GetSpellTargetLoc()
04-18-2004, 08:31 AM#4
Vidstige
All local variables must be declared first in a function. This would work:
Code:
function niceFunction takes nothing returns nothing
  local integer niceVar = 9*6
  call doSomething( niceVar )
endfunction
but this would not work:
Code:
function badFunction takes nothing returns nothing
  local integer niceVar = 9*6
  call doSomething( niceVar )
  local string badVar = "This is to late, must be above the call statement."
endfunction
If you still does not get it to work, you might consider posting your code.
04-18-2004, 02:42 PM#5
-={tWiStÄr}=-
it was called first. and I know how to make locals i have already have 1 in this trig and like a bunch in others. thats what i think jass is most usefull for ;) keeping the var box thing clean.
edit: oh and ill post my code in a little. im not on my comp right now.
edit2: ok, its the kind of error where wc3 doesnt load it.
Code:
function Trig_Frozen_Feet_ON_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00W' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Frozen_Feet_ON_Func005Func003001 takes nothing returns boolean
    return ( DistanceBetweenPoints(GetUnitLoc(GetSpellAbilityUnit()), Frozenfeetpoint) <= 50.00 )
endfunction

function Trig_Frozen_Feet_ON_Actions takes nothing returns nothing
    local location Frozenfeetpoint = GetSpellTargetLoc()
    local integer i = 1
    local real array speedbonus
    local real speedretain = GetUnitMoveSpeed(GetSpellAbilityUnit())
    set speedbonus[1] = 100
    set speedbonus[2] = 125
    set speedbonus[3] = 150
    set speedbonus[4] = 175
    set speedbonus[5] = 200
    set Frozenfeetpoint = GetSpellTargetLoc()
    //set udg_Frozenfeetpoint = GetSpellTargetLoc() i enable this when im using globals and it works fine
    call TriggerSleepAction( 1.00 )
    call SetUnitMoveSpeed( GetSpellAbilityUnit(), ( GetUnitMoveSpeed(GetSpellAbilityUnit()) + speedbonus[GetUnitAbilityLevel(GetSpellAbilityUnit(), 'A00W')] ) )
    call SetUnitInvulnerable( GetSpellAbilityUnit(), true )
    call SetUnitVertexColor(GetSpellAbilityUnit(), 183, 255, 255, 255)
    loop
        exitwhen i > 100
        call IssuePointOrderLocBJ( GetSpellAbilityUnit(), "move", Frozenfeetpoint )
        call SelectUnitRemove( GetSpellAbilityUnit() )
        if ( Trig_Frozen_Feet_ON_Func005Func003001() ) then
            set i = 100
        else
            call DoNothing(  )
        endif
        call SetUnitAnimation( GetSpellAbilityUnit(), "Stand" )
        call TriggerSleepAction( 0.01 )
        set i = i + 1
    endloop     
    call SetUnitVertexColor(GetSpellAbilityUnit(), 255, 255, 255, 255)
    call SetUnitMoveSpeed( GetSpellAbilityUnit(), speedretain)
    set i = 1
endfunction

//===========================================================================
function InitTrig_Frozen_Feet_ON takes nothing returns nothing
    set gg_trg_Frozen_Feet_ON = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Frozen_Feet_ON, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Frozen_Feet_ON, Condition( function Trig_Frozen_Feet_ON_Conditions ) )
    call TriggerAddAction( gg_trg_Frozen_Feet_ON, function Trig_Frozen_Feet_ON_Actions )
endfunction
04-18-2004, 06:10 PM#6
Vidstige
You will probably start to hate locals when I tell you this:
Code:
function Trig_Frozen_Feet_ON_Func005Func003001 takes nothing returns boolean
    return ( DistanceBetweenPoints(GetUnitLoc(GetSpellAbilityUnit()), Frozenfeetpoint) <= 50.00 )
endfunction
This is the thoughts of the compiler: Ah, a function, calculating distance between the location of this unit and ... eh? What is Frozenfeetpoint? It can't be a global, it has no udg_ in front. But there are no parameters or locals in this function with the name Frozenfeetpoint. What to do now? If some thinks that I am going to check if there are a local by that name in some other function... well, they might want to rethink. Well, I guess that the easiest way for me to handle this is to either spit out some strange error message, or just crash. I think I will try to do both at the same time...

How about replacing
Code:
if ( Trig_Frozen_Feet_ON_Func005Func003001() ) then
            set i = 100
        else
            call DoNothing(  )
        endif
with
Code:
if ( DistanceBetweenPoints(GetUnitLoc(GetSpellAbilityUn  it()), Frozenfeetpoint) <= 50.00 ) then
            set i = 100
        endif
and erase the function that breaks the code.

You might also want to consider rewriting
Code:
function Trig_Frozen_Feet_ON_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00W' ) ) then
        return false
    endif
    return true
endfunction
as
Code:
function Trig_Frozen_Feet_ON_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A00W' ) 
endfunction
or just delete the function and insert the expression into the code instead of the call to this function. But now I have been talkin way to much probably. Hope the locals haven't got cold feets be this. ;)
04-18-2004, 10:00 PM#7
-={tWiStÄr}=-
no, not at all locals are still cool ;) its prolly better to have it in the main function anyways so its more organized :\ or maybe its more one..ness like eh...
Thanks :D