• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

locals are only supported at the top of the function

Status
Not open for further replies.
You can only create a local at the start of a function. I'll give an example in JASS:
JASS:
function Example takes nothing returns nothing
    local integer i = 0 // valid
    local real x = 5 // valid
    call BJDebugMsg("Hello World")
    set i = 24 // valid
    local integer zz = 5 // error
endfunction

Locals are all supposed to be generated at the top of the function before any other functions have been called. Essentially, it should be declared before any "set", "call", "loop", etc. You can set them anywhere in the function though (as shown above).

In GUI's case, you have to be careful, because some things are in separate functions even when they might not seem to be. For example, the "Pick every unit..." function won't have access to the locals of that trigger.
 
Level 12
Joined
Nov 3, 2013
Messages
989
Would a wait action matter? I'm using custom script to have local variables

  • -------- Triggering Unit --------
  • Custom script: local unit udg_tempUnit = GetTriggerUnit()
  • -------- Name of triggering unit --------
  • Custom script: local string udg_unitTypeString = GetUnitName(udg_tempUnit)
  • -------- String lenght of name of triggering unit --------
  • Custom script: local integer udg_tempInt = StringLength(udg_unitTypeString)
  • -------- expiration timer for visual --------
  • Unit - Add a 26.00 second Animate Dead expiration timer to tempUnit
  • -------- actual duration --------
  • Wait 25.00 seconds
  • -------- revert new unit back to old unit type --------
  • Custom script: local location udg_tempPoint = Location( GetUnitX( udg_tempUnit), GetUnitY( udg_tempUnit))
  • Unit - remove tempUnit
  • Unit - Create 1 (Unit-type((Substring(unitTypeString, 11, tempInt)))) for (Owner of tempUnit) at tempPoint facing Default building facing degrees
  • Custom script: set udg_tempUnit = null
  • Custom script: call RemoveLocation( udg_tempPoint)
  • Custom script: set udg_tempPoint = null
the error/problem/whatever message refers to this:
local location udg_tempPoint = Location(GetUnitX(udg_tempUnit), GetUnitY(udg_tempUnit))
 
Yeah, a wait action matters. So you would basically declare it at the top and then set it after the wait:
  • Custom script: local integer udg_tempInt = StringLength(udg_unitTypeString)
  • Custom script: local location udg_tempPoint
  • -------- expiration timer for visual --------
  • Unit - Add a 26.00 second Animate Dead expiration timer to tempUnit
  • -------- actual duration --------
  • Wait 25.00 seconds
  • -------- revert new unit back to old unit type --------
  • Custom script: set udg_tempPoint = Location( GetUnitX( udg_tempUnit), GetUnitY( udg_tempUnit))
Also make sure you are using JassNewGenPack. I don't think the regular editor supports shadowing anymore.
 
It was all right they said... just wanted to throw in you would not need these local declarationen in that case.

TriggeringUnit/DyingUnit also work with combination with the wait-function, so you can set a normal globalVariable = TriggeringUnit after these 25 seconds.

And btw GetUnitName was not the correct function to get the UnitType. The correct one would be GetUnitTypeId(whichunit) ... and returns an integer.

Also "Owner of tempUnit" would be invalid I think, because you remove the "tempUnit" one line before.
 
Level 12
Joined
Nov 3, 2013
Messages
989
Yeah, a wait action matters. So you would basically declare it at the top and then set it after the wait:

Well then this is troublesome, because naturally the unit would not stay in the same place for the duration of the wait...

It was all right they said... just wanted to throw in you would not need these local declarationen in that case.

TriggeringUnit/DyingUnit also work with combination with the wait-function, so you can set a normal globalVariable = TriggeringUnit after these 25 seconds.

And btw GetUnitName was not the correct function to get the UnitType. The correct one would be GetUnitTypeId(whichunit) ... and returns an integer.

Also "Owner of tempUnit" would be invalid I think, because you remove the "tempUnit" one line before.

You see I want it to be string so I can remove the first letters and get the 'original' unit type.

And yeah whoops, It used to be "replace unit" but for some reason no unit would be created so I'm going with remove & create now instead.

Also make sure you are using JassNewGenPack. I don't think the regular editor supports shadowing anymore.

I do use the WE NewGen but I haven't dared touch any of the new things with it, so if there's something I would have to enable myself for it to work then I haven't done so.

Edit: I realised I could just use a normal set tempPoint = unit position of tempUnit, don't really get why the global work while local doesn't but w/e.

Also I think icemanBo might have ment that GetUnitName would give me 'proper name' while GetUnitTypeId give the name of the unit type (which is what I intended) so I changed that too, but now I've got a new problem.

But it says It's an integer instead of a string so I don't even know what's going on.
 
Status
Not open for further replies.
Top