An issue with a dialog

soulreaping

New Member
Reaction score
17
Hey,
I'm building a nice Stratego map (if anyone knows this classic strategy game) and I'm having an issue with a dialog.

Trigger 1:
JASS:

scope PlacingPhasePlayerOne

private function Conditions takes nothing returns boolean
    return (IsUnitAlly(GetTriggerUnit(), Player(0)))
endfunction

private function Actions takes nothing returns nothing
    set PlacingPhaseDialogP1 = DialogCreate()
    if (Player1Marshal == 1) then
        set Player1MarshalB = DialogAddButton(PlacingPhaseDialogP1, "Marshal (x1)", 0)
    endif
    if (Player1General == 1) then
        set Player1GeneralB = DialogAddButton(PlacingPhaseDialogP1, "General (x1)", 0)
    endif
    if (Player1Colonels > 0) then
        set Player1ColonelsB = DialogAddButton(PlacingPhaseDialogP1, "Colonels (x" + I2S(Player1Colonels)+")", 0)
    endif
    if (Player1Majors > 0) then
        set Player1MajorsB = DialogAddButton(PlacingPhaseDialogP1, "Majors (x" + I2S(Player1Majors) + ")", 0)
    endif
    if (Player1Captains > 0) then
        set Player1CaptainsB = DialogAddButton(PlacingPhaseDialogP1, "Captains (x" + I2S(Player1Captains) + ")", 0)
    endif
    if (Player1Lieutenants > 0) then
        set Player1LieutenantsB = DialogAddButton(PlacingPhaseDialogP1, "Lieutenants (x" + I2S(Player1Lieutenants) + ")", 0)
    endif
    if (Player1Sergeants > 0) then
        set Player1SergeantsB = DialogAddButton(PlacingPhaseDialogP1, "Sergeants (x" + I2S(Player1Sergeants) + ")", 0)
    endif
    if (Player1Miners > 0) then
        set Player1MinersB = DialogAddButton(PlacingPhaseDialogP1, "Miners (x" + I2S(Player1Miners) + ")", 0)
    endif
    if (Player1Scouts > 0) then
        set Player1ScoutsB = DialogAddButton(PlacingPhaseDialogP1, "Scouts (x" + I2S(Player1Scouts) + ")", 0)
    endif
    if (Player1Bombs > 0) then
        set Player1BombsB = DialogAddButton(PlacingPhaseDialogP1, "Bombs (x" + I2S(Player1Bombs) + ")", 0)
    endif
    if (Player1Spy == 1) then
        set Player1SpyB = DialogAddButton(PlacingPhaseDialogP1, "Spy (x1)", 0)
    endif
    if (Player1Flag == 1) then
        set Player1FlagB = DialogAddButton(PlacingPhaseDialogP1, "Flag (x1)", 0)
    endif   
     set TempP1Selection = GetTriggerUnit()
    call DialogDisplay(Player(0), PlacingPhaseDialogP1, true)
endfunction

public function InitTrig takes nothing returns nothing 
    local trigger myTrig = CreateTrigger()
    call TriggerRegisterPlayerSelectionEventBJ(myTrig, Player(0), true)
    call TriggerAddCondition(myTrig, Condition(function Conditions))
    call TriggerAddAction(myTrig, function Actions)
endfunction

endscope


This works pretty fine. The issue is here:
JASS:

scope ButtonMarshalPOne

globals
    private constant integer UNIT_ID = 'h003'
endglobals

private function Conditions takes nothing returns boolean
    return (GetClickedButton() == Player1MarshalB)
endfunction

private function Actions takes nothing returns nothing
    local location loc = GetUnitLoc(TempP1Selection)
    set Player1Marshal = 0
    call BJDebugMsg("Hello") // <-- To check if this function is even called.
    call RemoveUnit(TempP1Selection)
    call CreateUnitAtLoc(Player(0), UNIT_ID, loc, bj_UNIT_FACING)
    call DialogDestroy(PlacingPhaseDialogP1)
    call RemoveLocation(loc)
    set Player1MarshalB = null
    set loc = null
    set TempP1Selection = null
    call DisableTrigger(GetTriggeringTrigger())
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

public function InitTrig takes nothing returns nothing
    local trigger myTrig = CreateTrigger()
    call TriggerRegisterDialogButtonEvent(myTrig, Player1MarshalB)
    //call TriggerAddCondition(myTrig, Condition(function Conditions)) <-- I tried TriggerRegisterDialogEvent which then requires the condition.
    call TriggerAddAction(myTrig, function Actions)
endfunction
  
endscope


All variables are global variables.

Now in-game, when I click the Marshal button, it does nothing.

The unit isn't being replaced, the unit that is suppose to be created, isn't being created.

I don't get what I miss here.

Thanks for everyone who helps!
 

darkbeer

Beer is Good!
Reaction score
84
hm its just a guess, but if you use CreateUnit, you need to set a variable, mby its the same with CreateUnitAtLoc

so try this, i hope it helps:

JASS:
scope ButtonMarshalPOne

globals
    private constant integer UNIT_ID = 'h003'
endglobals

private function Conditions takes nothing returns boolean
    return (GetClickedButton() == Player1MarshalB)
endfunction

private function Actions takes nothing returns nothing
    local location loc = GetUnitLoc(TempP1Selection)
    local unit u

    set Player1Marshal = 0
    call BJDebugMsg("Hello") // <-- To check if this function is even called.
    call RemoveUnit(TempP1Selection)
    set u =  CreateUnitAtLoc(Player(0), UNIT_ID, loc, bj_UNIT_FACING) // Set it to a variable
    call DialogDestroy(PlacingPhaseDialogP1)
    call RemoveLocation(loc)
    set Player1MarshalB = null
    set loc = null
    set u = null
    set TempP1Selection = null
    call DisableTrigger(GetTriggeringTrigger())
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

public function InitTrig takes nothing returns nothing
    local trigger myTrig = CreateTrigger()
    call TriggerRegisterDialogButtonEvent(myTrig, Player1MarshalB)
    //call TriggerAddCondition(myTrig, Condition(function Conditions)) <-- I tried TriggerRegisterDialogEvent which then requires the condition.
    call TriggerAddAction(myTrig, function Actions)
endfunction
  
endscope


ähm i assume the hello message is displayed?

EDIT: hm, try adding a debug message to the initalizion trigger to see if its initalized
 

Tom Jones

N/A
Reaction score
437
And your sure that function runs?

*Edit*
The dialog isn't created when the event is added to the trigger.
 

soulreaping

New Member
Reaction score
17
Can you show me what lines are you talking about?

I just didn't really understand what you meant.
 

Tom Jones

N/A
Reaction score
437
JASS:
    call TriggerRegisterDialogButtonEvent(myTrig, Player1MarshalB)
When that part is called, the dialog isn't created yet (Since the dialog is first created when a player selects a unit, however the trigger tries to register the dialog during map load). Thus the dialog registered is null, and the trigger wont work.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top