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

scope destroys everything...

Status
Not open for further replies.
Level 9
Joined
Aug 21, 2008
Messages
533
I wrote this scope, and suddenly nothing is working anymore =/
when i delete it everything is working fine again, but i need it
JASS:
scope Dialog initializer INIT2

globals
private dialog Dialog 
private button array DialogButton
endglobals

private function Dialogfu takes nothing returns nothing
    local unit u =GetTriggerUnit()
    local player p=GetOwningPlayer(u)
    local integer id=GetPlayerId(p)
    local integer count=0
    if GetUnitLevel(u) == 2 then
        if GetUnitTypeId(u) == 'H000' then
            call DialogClear(Dialog)
            call DialogSetMessage( Dialog, "Choose your first Mastery" )
            set DialogButton[id*10] = DialogAddButton( Dialog, "Defender" ,0)
            //set udg_DialogButton[ id*10+1] = DialogAddButton( udg_Dialog[id], "test-do not click" ,0)
            call DialogDisplay((p), Dialog,true )
           loop
               call SaveInteger(udg_HashTable,id,StringHash("item"+I2S(count)),GetItemTypeId(UnitItemInSlot(u,count)))
                exitwhen count==5
                set count=count+1
            endloop
            call RemoveUnit(u)
        endif
    endif
    set u=null
    set p= null
endfunction

private function Click takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local unit u
    local integer count=0
    local integer id=GetPlayerId(p)
    local item i
    if GetClickedButton() == DialogButton[id*10] then
        set u =CreateUnitAtLoc(p,'H008', GetUnitLoc(gg_unit_nfoh_0027), bj_UNIT_FACING )
        call SetHeroLevel( u, 2, false )
        set CamU[GetPlayerId(p)]=u
        call AdjustPlayerStateBJ( -5, p, PLAYER_STATE_RESOURCE_LUMBER )
        call AdjustPlayerStateBJ( -1, p, PLAYER_STATE_RESOURCE_GOLD )
    endif
    loop
        set i =CreateItem(LoadInteger(udg_HashTable,id,StringHash("item"+I2S(count))),0,0)
        call UnitAddItem(u,i)
        exitwhen count==5
        set count=count+1
    endloop
    set u=null
    set p = null
endfunction

//===========================================================================
private function INIT2 takes nothing returns nothing
    local trigger click = CreateTrigger(  )
    local trigger dia  = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( dia, EVENT_PLAYER_HERO_LEVEL )
    call TriggerAddAction( dia, function Dialogfu )
    call TriggerRegisterDialogEvent(click, Dialog )
    call TriggerAddAction( click, function Click )
endfunction

endscope

edit: before i made it into a scope, i tested it as normal jass functions and this way it was working fine....
 
Call it init and not INIT2, why do you write those names in capital?
And get a better indenting. Here is how it should look like:

JASS:
scope Dialog initializer init
    globals
        private dialog Dialog  // Why is this capitalized?
        // How can this be MUI/MPI if you only have one dialog?
        private button array DialogButton // Why is this capitalized?
        // WE ONLY CAPITALIZE CONSTANTS!
        // private constant string EXAMPLE_CONSTANT = "WEE THIS IS IT!"
    endglobals
    
    private function fu takes nothing returns nothing
        local unit      u       = GetTriggerUnit()
        local player    p       = GetOwningPlayer(u)
        local integer   id      = GetPlayerId(p)
        local integer   count   = 0
        
        if GetUnitLevel(u) == 2 then
            if GetUnitTypeId(u) == 'H000' then
                call DialogClear(Dialog)
                call DialogSetMessage( Dialog, "Choose your first Mastery" )
                set DialogButton[id*10] = DialogAddButton( Dialog, "Defender" ,0)
                //set udg_DialogButton[ id*10+1] = DialogAddButton( udg_Dialog[id], "test-do not click" ,0)
                call DialogDisplay((p), Dialog,true )
               loop
                   call SaveInteger(udg_HashTable,id,StringHash("item"+I2S(count)),GetItemTypeId(UnitItemInSlot(u,count)))
                    exitwhen count==5
                    set count=count+1
                endloop
                call RemoveUnit(u)
            endif
        endif
        
        set u = null
        set p = null
    endfunction
    
    private function Click takes nothing returns nothing
        local player p = GetTriggerPlayer()
        local unit u // Why are these undeclared?
        local integer count = 0
        local integer id = GetPlayerId(p)
        local item i // Why are these undeclared?
        
        if GetClickedButton() == DialogButton[id*10] then
            set u = CreateUnitAtLoc(p,'H008', GetUnitLoc(gg_unit_nfoh_0027), bj_UNIT_FACING )
            call SetHeroLevel( u, 2, false )
            set CamU[GetPlayerId(p)] = u
            call AdjustPlayerStateBJ( -5, p, PLAYER_STATE_RESOURCE_LUMBER )
            call AdjustPlayerStateBJ( -1, p, PLAYER_STATE_RESOURCE_GOLD )
        endif
        
        loop
            set i = CreateItem(LoadInteger(udg_HashTable,id,StringHash("item"+I2S(count))),0,0)
            call UnitAddItem(u,i)
            exitwhen count == 5
            set count = count+1
        endloop
        
        set u = null
        set p = null
    endfunction
    
    //===========================================================================
    private function init takes nothing returns nothing
        local trigger click = CreateTrigger()
        local trigger dia  = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ( dia, EVENT_PLAYER_HERO_LEVEL )
        call TriggerAddAction( dia, function fu )
        call TriggerRegisterDialogEvent(click, Dialog )
        call TriggerAddAction( click, function Click )
    endfunction

endscope

// You better get better names for functions and variables, here a few examples:
// functions are ALWAYS beginning with a small capitalized word, f.e.
// function takeThisForExample.
// local variables are ALWAYS small capitalized.
// static and constant variables are both ALWAYS CAPITALIZED. 
// Make your code cleaner by using more spaces, more comments, more visual feedback
// to get more information in less time
 
Level 9
Joined
Aug 21, 2008
Messages
533
1 dialog is enough for being MPI, only the buttons are important.
all player see the same dialog, but after every player have different buttons on it =)

u and i where undiclared, cause first i needed to get which button was pressed.

I always capitalize globals, altought you right, cause there isnt a need for do this in a scope =/

But wy does it not work? Actually wc3 itself does not care how i write it =/

and more important: wy it kills the rest of my code?
 
1 dialog is enough for being MPI, only the buttons are important.
all player see the same dialog, but after every player have different buttons on it =)
It's a bad idea. Really.

u and i where undiclared, cause first i needed to get which button was pressed.
Undeclared variables crashes code when they are unused.

I always capitalize globals, altought you right, cause there isnt a need for do this in a scope =/
Please capitalize like I did.

But wy does it not work? Actually wc3 itself does not care how i write it =/

and more important: wy it kills the rest of my code?
Check the stuff about undeclaration.
 
Level 9
Joined
Aug 21, 2008
Messages
533
I first wrote it wouthout JNGP, so it was with Init_Trig. I deleted all the old globals, so it looks liek this cant be the prob.

I nulled i und u at the decleration so they are not undeclared anymore, but its still not working.

I dont get wy its a bad idea to show all players the same dialog. There are no interactions with it, just the buttons are important. If there is something i dont know tell me, but i dont see a flaw.

After a more testing, this line seems to cause the the problem:
JASS:
call TriggerRegisterDialogEvent(click, Dialog )
 
Status
Not open for further replies.
Top