• 🏆 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!

dialog doesnt appear, but screen freezes

Status
Not open for further replies.
Level 7
Joined
Jan 30, 2011
Messages
267
i am using the following code to create a dialog with 2 buttons: 1 to create a unit, 1 to close the dialog
when i hit escape (the event to open the dialog), the screen freezes and gets a bit darker (similiar to when you press F9-F12), but the dialog doesnt show up

EDIT: when i remove the line call DialogSetMessage(Spawn, "Spawn?"), then it works

JASS:
library SpawnDialog initializer init
    globals
        private dialog Spawn = DialogCreate()
        private button SiegeTank = DialogAddButton(Spawn, "Siege Tank", 0)  
        
        private button Cancel = DialogAddButton(Spawn, "Cancel", 0)
    endglobals
    
    function SpawnSiegeTank takes nothing returns nothing
        call CreateUnitAtLoc(Player(0), 'h007',GetRandomLocInRect(bj_mapInitialPlayableArea), GetRandomReal(0, 360) )
    endfunction
    
    function ShowSpawnDialog takes nothing returns nothing
        call DialogDisplay(Player(0), Spawn, true)
    endfunction

    function init takes nothing returns nothing
        local trigger trig1 = CreateTrigger()
        local trigger trig2 = CreateTrigger()
        
        call DialogSetMessage(Spawn, "Spawn?")
        call TriggerRegisterDialogButtonEvent(trig1, SiegeTank)
        call TriggerAddAction(trig1, function SpawnSiegeTank)
        
        call TriggerRegisterPlayerEvent(trig2, Player(0), EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(trig2, function ShowSpawnDialog)
        
        set trig1 = null
        set trig2 = null
    endfunction
endlibrary
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
You cannot create Dialogs at map initialization.

The global variable decleration...
private dialog Spawn = DialogCreate()
Makes an invalid Dialog as it fires during map initialization.

The function decleration used as library initializaer...
function init takes nothing returns nothing
interacts bugs the Diablo as it interacts with it during map initialization.

1. Create the dialog object atleast 0 seconds after map initialization (timer with timeout 0).
2. Display the dialog atleast after 0 seconds after map initialization (same as above).
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
That is a reason why I do not like to use the map initialization event for anything involving objects and content stuff. Instead relocate it after the loading screen. vJass should be updated there though to be able to shift the initializer calls outside of the main function.
 
Level 7
Joined
Jan 30, 2011
Messages
267
thx guys
it seems to be as dsg said
when you create a dialog on map initialization, you can properly add buttons to it
but when you try to set the dialog head message, then it bugs

it properly works like this:
JASS:
library SpawnDialog initializer preinit
    globals
        private timer initt = CreateTimer()
        private dialog Spawn //= DialogCreate()
        private button SiegeTank //= DialogAddButton(Spawn, "Siege Tank", 0)  
        
        private button Cancel //= DialogAddButton(Spawn, "Cancel", 0)
    endglobals
    
    function SpawnSiegeTank takes nothing returns nothing
        local location loc = GetRandomLocInRect(bj_mapInitialPlayableArea)
        call CreateUnitAtLoc(Player(0), 'h007', loc, GetRandomReal(0, 360) )
        call RemoveLocation(loc)
        set loc = null
    endfunction
    
    function ShowSpawnDialog takes nothing returns nothing
        call DialogDisplay(Player(0), Spawn, true)
    endfunction
    
    function init takes nothing returns nothing
        local trigger trig1 = CreateTrigger()
        local trigger trig2 = CreateTrigger()
        
        call DestroyTimer(initt)
        
        set Spawn = DialogCreate()
        set SiegeTank = DialogAddButton(Spawn, "Siege Tank", 0)  
        set Cancel = DialogAddButton(Spawn, "Cancel", 0)
        
        call DialogSetMessage(Spawn, "Spawn?")
        call TriggerRegisterDialogButtonEvent(trig1, SiegeTank)
        call TriggerAddAction(trig1, function SpawnSiegeTank)
        
        call TriggerRegisterPlayerEvent(trig2, Player(0), EVENT_PLAYER_END_CINEMATIC)
        call TriggerAddAction(trig2, function ShowSpawnDialog)
        
        set trig1 = null
        set trig2 = null
    endfunction
    
    function preinit takes nothing returns nothing
        call TimerStart(initt, 0, false, function init)
    endfunction
endlibrary
 
Status
Not open for further replies.
Top