HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Local 'Location'(Point) Var Doesn't Work?

12-12-2003, 08:17 PM#1
Extrarius
I'm making a teleport spell simmilar to mass teleport except that it doesn't stop the target unit, and it moves you to where they were when you started casting it, but I'm having some problems with a local variable in the script.
The problem is that none of the actions that use TempPoint get executed if I have it declared as a local variable. When I disable the line to make it a local variable, the code works fine. I checked the custom text to make sure it was all in the same function (so the local variable is accessable to all the code). Any ideas?
The code I have is:

Event:
Unit - A unit Is issued an order targeting an object

Conditions:
(Issued order) Equal to (Order(antimagicshell))
(Unit-type of (Target unit of issued order)) Equal to Holy Man

Actions:
Custom script: local location udg_TempPoint = null
Set TempPoint = (Position of (Target unit of issued order))
...
Wait 0.45 game-time seconds
...
Unit - Move (Ordered unit) instantly to TempPoint
12-12-2003, 08:22 PM#2
Youma
Waits reset ordered unit I think, try saving that in a variable allso.
12-12-2003, 08:28 PM#3
35263526
Youma is correct. Wait resets Casting Unit, Order Unit, Target Uit of Issued Order and Target Point of Issued Order.
12-12-2003, 08:31 PM#4
Extrarius
It still happens if I save ordered unit. It only happens when I have TempPoint as a local variable. When I leave it global, it works fine.
12-12-2003, 08:35 PM#5
35263526
Hmm, that is strange.

Are you sure that only one function is used?

If so, then I have a tiny idea. Take out the ' = null' from the line where you declare the local.

I know that it shouldn't have any effect, but it might be worth a try.
12-12-2003, 08:40 PM#6
Extrarius
You're right, it doesn't make any difference. I just put that in there as an attempt to fix it and I was too lazy to take it out =-)

As you can see from the custom text below, all the stuff accessing the local point is in the same function:

function Trig_Spell_Teleport_Conditions takes nothing returns boolean
if ( not ( GetIssuedOrderIdBJ() == String2OrderIdBJ("antimagicshell") ) ) then
return false
endif
if ( not ( GetUnitTypeId(GetOrderTargetUnit()) == 'H000' ) ) then
return false
endif
return true
endfunction

function Trig_Spell_Teleport_Actions takes nothing returns nothing
local unit udg_TempUnit
local location udg_TempPoint = null
set udg_TempPoint = GetUnitLoc(GetOrderTargetUnit())
set udg_TempUnit = GetOrderedUnit()
call TriggerSleepAction( 0.01 )
call IssueImmediateOrderBJ( udg_TempUnit, "stop" )
call TriggerSleepAction( 0.01 )
call SetUnitInvulnerable( udg_TempUnit, true )
call PauseUnitBJ( true, udg_TempUnit )
call PolledWait( 0.45 )
call PauseUnitBJ( false, udg_TempUnit )
call SetUnitInvulnerable( udg_TempUnit, false )
call TriggerSleepAction( 0.01 )
call SetUnitPositionLoc( udg_TempUnit, udg_TempPoint )
endfunction

//===========================================================================
function InitTrig_Spell_Teleport takes nothing returns nothing
set gg_trg_Spell_Teleport = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Spell_Teleport, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddCondition( gg_trg_Spell_Teleport, Condition( function Trig_Spell_Teleport_Conditions ) )
call TriggerAddAction( gg_trg_Spell_Teleport, function Trig_Spell_Teleport_Actions )
endfunction
12-12-2003, 08:43 PM#7
35263526
Thats your problem.

A local has to be declared at the start of a trigger. You have a function before it. You can't have If/Then/Else actions in a trigger with a local.
12-12-2003, 09:42 PM#8
Extrarius
Hrmm, apparently the problem is something to do with having 2 locals, because if I disable only one of them, the function works as it should. Looking through blizzard.j, I find functions with multiple locals, so I'm wondering what the problem is.

Also, note that the locals ARE at the start of the trigger actions, they are the first thing done inside the function.
12-13-2003, 09:42 PM#9
Vexorian
In fact, I think it is something about using my method for this, try temporary disabling the gui trigger, copy it and convert it to jass, then remove every udg_ you can find, try the trigger again, then if it is working then our beloved method is stupid.
12-13-2003, 10:21 PM#10
Extrarius
It works without the udg_, so there must be some weird 'bug' in jass that only lets you override a single global variable in each function or something like that. Since I posted this I've done a LOT of jass coding and I'm starting to memorize the api etc so maybe I'll just leave it custom text (before you suggested that I had just made a global array for each variable since I only need to store 1 set of teleport info per player)