HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Local variable issues

01-26-2008, 03:12 PM#1
Centreri
Can anyone tell me what exactly is the error in the following spell? I'm pretty sure that it's the local variables, since when I used this spell in an experimental map and used arrays instead of locals it worked fine. It won't compile.

Trigger:
Replay
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Replay
Collapse Actions
Custom script: local Real udg_ReplayLife
Custom script: local Point udg_ReplayPosition
Custom script: local Unit udg_ReplayUnit
Set ReplayLife = (Percentage life of (Target unit of ability being cast))
Set ReplayPosition = (Position of (Target unit of ability being cast))
Set ReplayUnit = (Target unit of ability being cast)
Wait 5.00 seconds
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
HeroStatus[(Player number of (Owner of (Target unit of ability being cast)))] Not equal to Dead
HeroStatus[(Player number of (Owner of (Target unit of ability being cast)))] Not equal to Undead
HeroStatus[(Player number of (Owner of (Target unit of ability being cast)))] Not equal to Unlife
Collapse Then - Actions
Unit - Set life of ReplayUnit to ReplayLife%
Unit - Move ReplayUnit instantly to ReplayPosition
Special Effect - Create a special effect at (Position of (Target unit of ability being cast)) using Abilities\Spells\Demon\DarkPortal\DarkPortalTarget.mdl
Special Effect - Destroy (Last created special effect)
Collapse Else - Actions
Do nothing
Set ReplayPosition = (Center of (Playable map area))
Set ReplayLife = 0.00
Set ReplayUnit = No unit
Custom script: set udg_ReplayUnit = null
Custom script: set udg_ReplayPosition = null
Custom script: set udg_ReplayLife = null
01-26-2008, 03:17 PM#2
Ammorth
Quote:
Originally Posted by Centreri
Can anyone tell me what exactly is the error in the following spell? I'm pretty sure that it's the local variables, since when I used this spell in an experimental map and used arrays instead of locals it worked fine. It won't compile.

The GUI local trick only works on 1 local at a time. Don't ask why, thats just the way it is.
01-26-2008, 03:27 PM#3
Centreri
..My respect for Blizzard has fallen. Any way to get around this short of using arrays? This also seems to explain why another one of my spells hasn't worked properly, though it did compile.
01-26-2008, 04:12 PM#4
Ammorth
Quote:
Originally Posted by Centreri
..My respect for Blizzard has fallen. Any way to get around this short of using arrays?

Learning Jass would be the best solution. You can then have as many locals as you want.
01-26-2008, 04:26 PM#5
Troll-Brain
or the worst way is to keep your trigger in gui, deactivate it.
Then copy/paste your trigger, convert it in jass and finally remove the udg_
01-26-2008, 08:09 PM#6
Jitse
Everyone should use Jass, it's really not hard. Btw. Why are you giving your locals an udg_ prefix? :p
01-26-2008, 08:11 PM#7
TaintedReality
Quote:
Why are you giving your locals an udg_ prefix?

There's a trick to make globals in GUI behave as locals, so that GUI users can have locals. And all global variables created in GUI have the udg (user defined global) prefix.
01-26-2008, 08:12 PM#8
Ammorth
So he can still use the GUI menu's to select his variables. The problem is that using more than 1 duplicate variable (global and local of the same name) causes problems.

edit: TaintedReality beat me to the post :P
01-26-2008, 08:14 PM#9
TaintedReality
Hah. Too slow :).
01-26-2008, 09:05 PM#10
Jitse
Lol, why do companies never release a totally completed environment for modders... Probably because it's too much testing work.

Centreri, Jass is the way to go.
01-27-2008, 02:16 PM#12
Centreri
Eh. Okay, I'll try it one more time. If I get lazy this time too, back to GUI.
01-27-2008, 09:40 PM#13
Pyrogasm
First of all, you did the "trick" wrong. When declaring variables in JASS the "type" of the variable is never capitalized. You can't null a real, as you did to ReplayLife. Finally, a "point" is actually a "location":
Trigger:
Custom script: local real udg_ReplayLife
Custom script: local location udg_ReplayPosition
Custom script: local unit udg_ReplayUnit
Everyone's always so pessimistic about this approach, but it should work just fine:
Collapse JASS:
//Put this in your custom script section or just use it manually, it's really just here to not get you confused
function CloneLoc takes location L returns location
    return Location(GetLocationX(L), GetLocationY(L))
endfunction

Trigger:
Replay
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Replay
Collapse Actions
Custom script: local real ReplayLife
Custom script: local location ReplayPosition
Custom script: local unit udg_ReplayUnit
Set ReplayLife = (Percentage life of (Target unit of ability being cast))
Custom script: set ReplayLife = udg_ReplayLife
Set ReplayPosition = (Position of (Target unit of ability being cast))
Custom script: set ReplayPosition = CloneLoc(udg_ReplayPosition)
Custom script: call RemoveLocation(udg_ReplayPosition)
Set ReplayUnit = (Target unit of ability being cast)
Wait 5.00 seconds
Custom script: set udg_ReplayLife = ReplayLife
Custom script: set udg_ReplayLoc = ReplayLoc
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
HeroStatus[(Player number of (ReplayUnit))] Not equal to Dead
HeroStatus[(Player number of (ReplayUnit))] Not equal to Undead
HeroStatus[((Player number of (ReplayUnit))] Not equal to Unlife
Collapse Then - Actions
Unit - Set life of ReplayUnit to ReplayLife%
Unit - Move ReplayUnit instantly to ReplayPosition
Special Effect - Create a special effect at (ReplayPosition) using Abilities\Spells\Demon\DarkPortal\DarkPortalTarget.mdl
Special Effect - Destroy (Last created special effect)
Else - Actions
Set ReplayUnit = No unit
Custom script: call RemoveLocation(udg_ReplayPosition)
Custom script: set ReplayPosition = null
I also fixed some other errors you had in there.
01-27-2008, 09:44 PM#14
Vexorian
Quote:
Originally Posted by Centreri
..My respect for Blizzard has fallen. Any way to get around this short of using arrays? This also seems to explain why another one of my spells hasn't worked properly, though it did compile.
Because they didn't make shadowing correctly? Or because they actually made GUI?
01-28-2008, 09:59 PM#15
Centreri
Well, after learning a tiny bit of JASS (Vexorians tutorial is great), I got the spell working in the following manner. Mostly converting and editing.
Collapse JASS:
function Trig_Replay_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A010'
endfunction

function Trig_Replay_Func008C takes nothing returns boolean
    if ( not ( udg_HeroStatus[GetConvertedPlayerId(GetOwningPlayer(GetSpellTargetUnit()))] != "Dead" ) ) then
        return false
    endif
    if ( not ( udg_HeroStatus[GetConvertedPlayerId(GetOwningPlayer(GetSpellTargetUnit()))] != "Undead" ) ) then
        return false
    endif
    if ( not ( udg_HeroStatus[GetConvertedPlayerId(GetOwningPlayer(GetSpellTargetUnit()))] != "Unlife" ) ) then
        return false
    endif
    return true
endfunction

function Trig_Replay_Actions takes nothing returns nothing
    local real ReplayLife = GetUnitLifePercent(GetSpellTargetUnit())
    local location ReplayPosition = GetUnitLoc(GetSpellTargetUnit())
    local unit ReplayUnit = GetSpellTargetUnit()
    call TriggerSleepAction( 5.00 )
    if ( Trig_Replay_Func008C() ) then
        call SetUnitLifePercentBJ( ReplayUnit, ReplayLife )
        call SetUnitPositionLoc( ReplayUnit, ReplayPosition )
        call DestroyEffectBJ( AddSpecialEffectLocBJ( GetUnitLoc(GetSpellTargetUnit()), "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl" ) )
    endif
    set ReplayPosition = GetRectCenter(GetPlayableMapRect())
    set ReplayLife = 0.00
    set ReplayUnit = null
endfunction

//===========================================================================
function InitTrig_Replay takes nothing returns nothing
    set gg_trg_Replay = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Replay, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Replay, Condition( function Trig_Replay_Conditions ) )
    call TriggerAddAction( gg_trg_Replay, function Trig_Replay_Actions )
endfunction

Quote:
Finally, a "point" is actually a "location":
Ah. No wonder. That was a major breakthrough. Oh, and figuring out that I better enable the trigger to get it to work.

Quote:
Because they didn't make shadowing correctly? Or because they actually made GUI?
My serious response is because GUI doesn't allow multiple locals. You have to understand, my respect for Blizzard is very high, so if it goes a bit down, not much happens.

Thanks, everyone.