• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Line Converted from GUI doesn't work as Custom Script

Status
Not open for further replies.
Level 39
Joined
Feb 27, 2007
Messages
4,994
I'm super perplexed by this. Trying to get some buildings to rotate upon creation I wrote this trigger which works:

  • init working
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg("1")
      • Custom script: call UnitRemoveAbility(gg_unit_hbar_0051, 'Amov')
      • Custom script: call BJDebugMsg("2")
      • Unit - Make Barracks 0051 <gen> face 90.00 over 0.00 seconds
      • Custom script: call BJDebugMsg("3")
      • Unit - Kill Archmage 0000 <gen>
      • Custom script: call BJDebugMsg("4")
On map init I see the 1 2 3 4 messages, the building changes facing, and the Archmage is killed. If I convert the trigger to JASS I get the following trigger, which also works just as well as the above trigger.

JASS:
function Trig_init_Actions takes nothing returns nothing
    call BJDebugMsg("1")
    call UnitRemoveAbility(gg_unit_hbar_0051, 'Amov')
    call BJDebugMsg("2")
    call SetUnitFacingTimed( gg_unit_hbar_0051, 90.00, 0.00 )
    call BJDebugMsg("3")
    call KillUnit( gg_unit_Hamg_0000 )
    call BJDebugMsg("4")
endfunction

//===========================================================================
function InitTrig_init takes nothing returns nothing
    set gg_trg_init = CreateTrigger(  )
    call TriggerAddAction( gg_trg_init, function Trig_init_Actions )
endfunction
But if I just sneak the call SetUnitFacingTimed( gg_unit_hbar_0051, 90.00, 0.00 ) into the first trigger as a CS line instead of the GUI action, then things get real funky. I still see all 1 2 3 4 messages and the Archmage dies... but the unit's Move ability doesn't get removed and it doesn't change its facing. I presume the latter is a result of the former for the turning unit. Regardless, why the fuck would the UnitRemoveAbility() stop working once I replace a GUI line below that line with a literally identical Custom Script line? Trigger that doesn't work is below and a test map is attached so you can see for yourself:

  • init broken
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg("1")
      • Custom script: call UnitRemoveAbility(gg_unit_hbar_0051, 'Amov')
      • Custom script: call BJDebugMsg("2")
      • Custom script: call SetUnitFacingTimed( gg_unit_hbar_0051, 90.00, 0.00 )
      • Custom script: call BJDebugMsg("3")
      • Unit - Kill Archmage 0000 <gen>
      • Custom script: call BJDebugMsg("4")

Edit: If I convert "init broken" to JASS without so much as touching the actual trigger contents it works just fine. This appears to be some sort of bizarre GUI bug. I am running 1.29, not 1.30.
 

Attachments

  • teeest.w3x
    22.7 KB · Views: 21
This seems to be because you are no longer referencing the generated unit variable (Barracks 0051 <gen>) anywhere in GUI, and it is therefore deemed unused by the editor and never assigned any unit.
This means gg_unit_hbar_0051 will always be null.

  • init broken
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: if (gg_unit_hbar_0051 == null) then
      • Custom script: call BJDebugMsg("Barracks is null...")
      • Custom script: endif
      • Custom script: call BJDebugMsg("1")
      • Custom script: call UnitRemoveAbility(gg_unit_hbar_0051, 'Amov')
      • Custom script: call BJDebugMsg("2")
      • Custom script: call SetUnitFacingTimed( gg_unit_hbar_0051, 90.00, 0.00 )
      • Custom script: call BJDebugMsg("3")
      • Unit - Kill Archmage 0000 <gen>
      • Custom script: call BJDebugMsg("4")
You can confirm this by putting ANY GUI action that references the barracks in ANY trigger and it will magically work again (both the trigger and the action has to be enabled).

  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Unit - Set the custom value of Barracks 0051 <gen> to 0

EDIT: It's strange. This seems to only be the case for GUI triggers and the map header.
If gg_unit_hbar_0051 is referenced in a pure custom text trigger the unit will be initialized.
Hence why converting the trigger to custom text works, but using custom script in GUI does not.



EDIT 2: It does not matter where or how the variable is used in a custom text trigger. It just has to be there. Somewhere. Anywhere. For instance, this will initialize the unit:
JASS:
//gg_unit_hbar_0051
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
endfunction
So will this:
JASS:
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    call BJDebugMsg("Hello gg_unit_hbar_0051 world!")
endfunction


EDIT 3: Here's the difference in the generated script file:
JASS:
function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p = Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set gg_unit_hfoo_0001 = CreateUnit( p, 'hfoo', -0.6, 4.9, 309.055 )
endfunction
JASS:
function CreateUnitsForPlayer0 takes nothing returns nothing
    local player p = Player(0)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u = CreateUnit( p, 'hfoo', -0.6, 4.9, 309.055 )
endfunction
 
Last edited:
You'd think so, but only units picked via the Select a Unit button will be assigned a global variable.
This generated variable will exist until the unit is deleted from the editor, but if the variable is only used in GUI custom script and/or the map header the editor will simply not assign any unit to it and it will remain null.
JASS:
globals
    // Generated
    unit                    gg_unit_hbar_0051          = null
endglobals
 
Status
Not open for further replies.
Top