Crazy weird error which fails whole map

inevit4ble

Well-Known Member
Reaction score
38
Hi Every1,

This problem is messed up by my standards.

In my spawn script a hero i created and a bunch of struct variables are set to certain criteria depending on the hero choice.
BJDebug shows me that the variables have a value but right after its finished running all variables become null
Its as if the unit somehow is removed and recreated.

Any idea why this would occur?
Relevant snippet:
JASS:
//===========================================================================
//=======================WaitPoint CharCreate================================
//===========================================================================
    private function wpCondition takes nothing returns boolean
        //Human Racial Bonus
        local unit  ut = GetTriggerUnit()
        local player p = GetOwningPlayer(ut)
        local integer d = GetPlayerId(p)
        local integer i
        
        //General Spell Book of game functions
        call UnitAddAbility(ut, 'A00B')
        //Feats Book
        call UnitAddAbility(ut, 'A00I')
        //Feat Point Set
        call AdjustPlayerStateBJ( 1, p, PLAYER_STATE_RESOURCE_FOOD_CAP )
        //Attribute Points
        call AdjustPlayerStateBJ( 28, p, PLAYER_STATE_RESOURCE_LUMBER )
        
        if Race[d] == 1 then //Dwarf
            set UD[ut].rac = "Dwarf"
            set UD[ut].str = 8
            set UD[ut].dex = 8
            set UD[ut].con = 10
            set UD[ut].inl = 8
            set UD[ut].wis = 8
            set UD[ut].cha = 6
            call BJDebugMsg("Dwarf")
        
        elseif Race[d] == 2 then //Elf
            set UD[ut].rac = "Elf"
            set UD[ut].str = 8
            set UD[ut].dex = 10
            set UD[ut].con = 6
            set UD[ut].inl = 8
            set UD[ut].wis = 8
            set UD[ut].cha = 8
        
        elseif Race[d] == 3 then //Gnome
            set UD[ut].rac = "Gnome"
            set UD[ut].str = 6
            set UD[ut].dex = 8
            set UD[ut].con = 10
            set UD[ut].inl = 8
            set UD[ut].wis = 8
            set UD[ut].cha = 8
            //Smaller in size so +1 AC gained
            set UD[ut].size = 1
        
        elseif Race[d] == 4 then //Half-Elf
            set UD[ut].rac = "Half-Elf"
            set UD[ut].str = 8
            set UD[ut].dex = 8
            set UD[ut].con = 8
            set UD[ut].inl = 8
            set UD[ut].wis = 8
            set UD[ut].cha = 8
        
        elseif Race[d] == 5 then //Half-Orc
            set UD[ut].rac = "Half-Orc"
            set UD[ut].str = 10
            set UD[ut].dex = 8
            set UD[ut].con = 8
            set UD[ut].inl = 6
            set UD[ut].wis = 8
            set UD[ut].cha = 6
        
        elseif Race[d] == 6 then //Halfling
            set UD[ut].rac = "Halfling"
            set UD[ut].str = 6
            set UD[ut].dex = 10
            set UD[ut].con = 8
            set UD[ut].inl = 8
            set UD[ut].wis = 8
            set UD[ut].cha = 8
            //Smaller in size so +1 AC gained
            set UD[ut].size = 1
        
        
        elseif Race[d] == 7 then //Human
            set UD[ut].rac = "Human"
            set UD[ut].str = 8
            set UD[ut].dex = 8
            set UD[ut].con = 8
            set UD[ut].inl = 8
            set UD[ut].wis = 8
            set UD[ut].cha = 8
            call AdjustPlayerStateBJ( 1, p, PLAYER_STATE_RESOURCE_FOOD_CAP )//Extra Food for Human
        endif
        
        //Barbarian
        if Class[d] == 1 then
            call BJDebugMsg("Barbarian")
            set UD[ut].cla = "Barbarian"
            //Set per class and grows with level
            set UD[ut].baseAttkBonus = 1 //Good
            call UnitAddAbility(ut, 'A000')
            //Start Gold
            set i = GetRandomInt(4, 16)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 11//runs 12 times?
            endloop
            //Proficiencies
            set UD[ut].equip[1] = "ws"
            set UD[ut].equip[2] = "wm"
            set UD[ut].equip[3] = "al"
            set UD[ut].equip[4] = "am"
            set UD[ut].equip[5] = "ss"
            set UD[ut].equip[6] = ""
            
            
            /*call SetPlayerAbilityAvailable( Player(i), lig, true)
            call SetUnitAbilityLevel(ut, lig, 2)
            call SetPlayerAbilityAvailable( Player(i), med, true)
            call SetUnitAbilityLevel(ut, med, 2)
            call SetPlayerAbilityAvailable( Player(i), sim, true)
            call SetUnitAbilityLevel(ut, sim, 2)
            call SetPlayerAbilityAvailable( Player(i), mar, true)
            call SetUnitAbilityLevel(ut, mar, 2)
            call SetPlayerAbilityAvailable( Player(i), shi, true)
            call SetUnitAbilityLevel(ut, shi, 2)*/
        
        //Bard
        elseif Class[d] == 2 then
            set UD[ut].cla = "Bard"
            set UD[ut].baseAttkBonus = 0 //Average
            call UnitAddAbility(ut, 'A001')//Class Skills
            call UnitAddAbility(ut, 'A00P')//Class Spells
            //Start Gold
            set i = GetRandomInt(4, 16)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 5 //
            endloop
            //Proficeincies
            set UD[ut].equip[1] = "ws"
            set UD[ut].equip[2] = "al"
            set UD[ut].equip[3] = "ss"
            set UD[ut].equip[4] = ""
            
            /*call SetPlayerAbilityAvailable( Player(i), lig, true)
            call SetUnitAbilityLevel(ut, lig, 2)
            call SetPlayerAbilityAvailable( Player(i), sim, true)
            call SetUnitAbilityLevel(ut, sim, 2)
            call SetPlayerAbilityAvailable( Player(i), shi, true)
            call SetUnitAbilityLevel(ut, shi, 2)*/
            //Special selection of weapons
        
        //Cleric
        elseif Class[d] == 3 then
            set UD[ut].cla = "Cleric"
            set UD[ut].baseAttkBonus = 0 //Average
            call UnitAddAbility(ut, 'A002')
            call UnitAddAbility(ut, 'A00Q')//Class Spells
            //Start Gold
            set i = GetRandomInt(5, 20)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 7 //
            endloop 
            //Proficiencies   
            set UD[ut].equip[1] = "al"
            set UD[ut].equip[2] = "am"
            set UD[ut].equip[3] = "ah"
            set UD[ut].equip[4] = "ws"
            set UD[ut].equip[5] = "ss"
            set UD[ut].equip[6] = ""
        
            /*call SetPlayerAbilityAvailable( Player(i), lig, true)
            call SetUnitAbilityLevel(ut, lig, 2)
            call SetPlayerAbilityAvailable( Player(i), med, true)
            call SetUnitAbilityLevel(ut, med, 2)
            call SetPlayerAbilityAvailable( Player(i), hea, true)
            call SetUnitAbilityLevel(ut, hea, 2)
            call SetPlayerAbilityAvailable( Player(i), sim, true)
            call SetUnitAbilityLevel(ut, sim, 2)
            call SetPlayerAbilityAvailable( Player(i), shi, true)
            call SetUnitAbilityLevel(ut, shi, 2)*/
            
        //Druid
        elseif Class[d] == 4 then
            set UD[ut].cla = "Druid"
            set UD[ut].baseAttkBonus = 0 //Average
            call UnitAddAbility(ut, 'A003')
            call UnitAddAbility(ut, 'A00R')//Class Spells
            //Start Gold
            set i = GetRandomInt(2, 8)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 7 //
            endloop 
            //Proficiencies
            set UD[ut].equip[1] = "al"
            set UD[ut].equip[2] = "am"
            set UD[ut].equip[3] = "ss"
            set UD[ut].equip[4] = ""
            /*call SetPlayerAbilityAvailable( Player(i), lig, true)
            call SetUnitAbilityLevel(ut, lig, 2)
            call SetPlayerAbilityAvailable( Player(i), med, true)
            call SetUnitAbilityLevel(ut, med, 2)
            call SetPlayerAbilityAvailable( Player(i), shi, true)
            call SetUnitAbilityLevel(ut, shi, 2)*/
            //Special selection of weapons
            
        //Fighter
        elseif Class[d] == 5 then 
            set UD[ut].cla = "Fighter"
            set UD[ut].baseAttkBonus = 1 //Good
            call UnitAddAbility(ut, 'A004')
            //Start Gold
            set i = GetRandomInt(6, 24)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 9 //
            endloop 
            //Proficiencies            
            set UD[ut].equip[1] = "ws"
            set UD[ut].equip[2] = "wm"
            set UD[ut].equip[3] = "we"
            set UD[ut].equip[4] = "al"
            set UD[ut].equip[5] = "am"
            set UD[ut].equip[6] = "ah"
            set UD[ut].equip[7] = "ss"
            set UD[ut].equip[8] = "st"
        
        
        //Monk
        elseif Class[d] == 6 then
            set UD[ut].cla = "Monk"
            set UD[ut].baseAttkBonus = 0 //Average
            call UnitAddAbility(ut, 'A005')
            //Start Gold
            set i = GetRandomInt(5, 20)
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 7 //
            endloop 
            //Proficiencies         
            set UD[ut].equip[1] = "ws"
            set UD[ut].equip[2] = ""
            /*call SetPlayerAbilityAvailable( Player(i), lig, true)
            call SetUnitAbilityLevel(ut, lig, 2)
            call SetPlayerAbilityAvailable( Player(i), med, true)
            call SetUnitAbilityLevel(ut, med, 2)
            call SetPlayerAbilityAvailable( Player(i), hea, true)
            call SetUnitAbilityLevel(ut, hea, 2)
            call SetPlayerAbilityAvailable( Player(i), sim, true)
            call SetUnitAbilityLevel(ut, sim, 2)
            call SetPlayerAbilityAvailable( Player(i), mar, true)
            call SetUnitAbilityLevel(ut, mar, 2)
            call SetPlayerAbilityAvailable( Player(i), shi, true)
            call SetUnitAbilityLevel(ut, shi, 2)
            call SetPlayerAbilityAvailable( Player(i), twr, true)
            call SetUnitAbilityLevel(ut, twr, 2)*/
            
        //Paladin
        elseif Class[d] == 7 then 
            set UD[ut].cla = "Paladin"
            set UD[ut].baseAttkBonus = 1 //Good
            call UnitAddAbility(ut, 'A006')
            call UnitAddAbility(ut, 'A00S')//Class Spells
            //Start Gold
            set i = GetRandomInt(6, 24)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 9 //
            endloop 
        
        //Ranger
        elseif Class[d] == 8 then
            set UD[ut].cla = "Ranger"
            set UD[ut].baseAttkBonus = 1 //Good
            call UnitAddAbility(ut, 'A007')
            call UnitAddAbility(ut, 'A00T')//Class Spells
            //Start Gold
            set i = GetRandomInt(6, 24)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 7 //
            endloop 
            //Profs
            set UD[ut].equip[1] = "ws"
            set UD[ut].equip[2] = "wm"
            set UD[ut].equip[3] = "al"
            set UD[ut].equip[4] = "am"
            set UD[ut].equip[5] = "ah"
            set UD[ut].equip[6] = "ss"
            set UD[ut].equip[7] = ""
            
        
        //Rogue
        elseif Class[d] == 9 then
            set UD[ut].cla = "Rogue"
            set UD[ut].baseAttkBonus = 0 //Average
            call UnitAddAbility(ut, 'A008')
            //Start Gold
            set i = GetRandomInt(5, 20)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 5 //
            endloop 
            set UD[ut].equip[1] = "ws"
            set UD[ut].equip[2] = "wm"
            set UD[ut].equip[3] = "al"
            set UD[ut].equip[4] = "ss"
            set UD[ut].equip[5] = ""
                    
        //Sorcerer
        elseif Class[d] == 10 then
            set UD[ut].cla = "Sorcerer"
            set UD[ut].baseAttkBonus = 0 //Poor
            call UnitAddAbility(ut, 'A009')
            call UnitAddAbility(ut, 'A00O')//Class Spells
            //Start Gold
            set i = GetRandomInt(3, 12)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 3 //
            endloop 
            //Profs
            set UD[ut].equip[1] = "ws"
            
            
        //Wizard
        elseif Class[d] == 11 then
            set UD[ut].cla = "Wizard"
            set UD[ut].baseAttkBonus = 0 //Poor
            call UnitAddAbility(ut, 'A00A')
            call UnitAddAbility(ut, 'A00N')//Class Spells
            //Start Gold
            set i = GetRandomInt(3, 12)*10
            call AdjustPlayerStateBJ( i, p, PLAYER_STATE_RESOURCE_GOLD )
            set i = 0
            loop
                set i = i + 1
                //actions
                call UnitAddAbility(ut, 'A00M')
                call SetUnitAbilityLevel(ut, 'A00M', 2)
                call UnitRemoveAbility(ut, 'A00M')
                exitwhen i == 3 //
            endloop 
            set UD[ut].equip[1] = "ws"
            
        endif
        
        //Set depending on weapon. No weapon = 1
        set UD[ut].weapondmg = 3    //At start heroes have no weapon
                                    //Unarmed dmg is 1-3
                                    //This value needs to be set as default if weapon is unequiped
        
        //Bonus = (Stat - 10) / 2
        set i = UD[ut].str
        set UD[ut].strB = (i - 10) / 2
        set i = UD[ut].dex
        set UD[ut].dexB = (i - 10) / 2
        set i = UD[ut].con
        set UD[ut].conB = (i - 10) / 2
        set i = UD[ut].inl
        set UD[ut].inlB = (i - 10) / 2
        set i = UD[ut].wis
        set UD[ut].wisB = (i - 10) / 2
        set i = UD[ut].cha
        set UD[ut].chaB = (i - 10) / 2
        
        //AC = 10 + Armor + Shield + DexB + Natural + Delfection + Size + Misc
        //****THIS FORMULA IS ONLY FOR PLAYERS****\\
        //Creeps will have set ACs
        //set UD[ut].armorclass = 10 + UD[ut].armor + UD[ut].shield + UD[ut].dexB + UD[ut].nat + UD[ut].def + UD[ut].size + UD[ut].misc
        
        //Gives Multiboard Inventory to Hero
        call InitInventory(ut)
        
        //Leak Catch
        set ut = null
        set p = null
        
        return true
    endfunction
    
    private function wpActions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer i = 0
        local real x = GetRectCenterX(gg_rct_Beginning)
        local real y = GetRectCenterY(gg_rct_Beginning)
        
        
        set playerChar[GetPlayerId(GetOwningPlayer(u))] = u
        if playerWaiting == playerNum then
            loop
                exitwhen i == 4
                call SetUnitPosition(playerChar<i>, x, y)
                call PanCameraToTimed(x, y, 0.)
                set i = i + 1
            endloop
        else
            call DisplayTextToPlayer(GetOwningPlayer(u), 0., 0., &quot;Waiting for Players to complete selection&quot;)
        endif
        
        //Leak Catch
        set u = null
        
    endfunction
//===========================================================================
//=======================WaitPoint CharCreEnd================================
//===========================================================================
</i>

The only actions that occur after the setting is a moveUnit action.

We have tried almost everything to work this out and its driving me crazy!
 

dudeim

New Member
Reaction score
22
You're not destroying the struct later as that would make the values return 0 I think that's the only way it could show up like this.
 

inevit4ble

Well-Known Member
Reaction score
38
You're not destroying the struct later as that would make the values return 0 I think that's the only way it could show up like this.
I don't get it. I must destroy a struct to have variables retain the values?

@Dirac: Going to check it out. Only just learned structs. Baby steps :)
 

dudeim

New Member
Reaction score
22
I don't get it. I must destroy a struct to have variables retain the values?

@Dirac: Going to check it out. Only just learned structs. Baby steps :)
nonono if you're destroying the struct right after settings those values, the values would return 0 so you shouldn't destroy the struct right after setting the variables or just before you want the variables to show up. (in your case this struct would probably stay all the map long though so no need for destroying it)
So just check around if you didn't destroy it somewhere and if you did just remove that.
 

inevit4ble

Well-Known Member
Reaction score
38
Oh ok, ye I'm not destroying it anywhere.

What the strangest part is that there is one value, and one value only, that does retain its value. That is a unit variable
(UD[ut].unit = GetTriggerUnit())
Its not in the snippet but for some reason that variable retains its value. So so confusing. My partner believes it might just be a strange WE bug, so he has taken upon himself to rewrite the scripts but I'm sure there is something else.

Should a post the struct script and the rest of the snippet script? perhaps it will help? Its just very long...
 

Dirac

22710180
Reaction score
147
strange WE bug
I highly doubt that. Please clarify for us:

-Is UD an AIDS struct or what?
-Is Class an AIDS struct too?
-When does this trigger fire? (exactly)

Are you sure that those instances were allocated previous to the funcion?
Are you sure that the variables are even being set during the function? (use BJDebugMsgs to find this out)

BJDebugMsgs are your friend, fill your trigger with them and you'll eventually find the bug
 

inevit4ble

Well-Known Member
Reaction score
38
Ok,

-UD (Unit Dex) is not an AIDS struct.
-Class and Race are not structs, they are Integer Arrays
-Upon game start, player are given a "Spawning Wisp". The wisp allows them to select a race (Sets Race[]), then they choose a class (Sets Class[]). After those 2 selection are made the wisp is moved into a region which then removes the wisp and creates the hero from a hashtable based on Race&Class ((h, Race, Class) == UnitX). It then moves then hero into the "Waiting Room" (Heroes wait till everyone has finished chosing then moved into the map)

When the hero enters the waiting point this snippet fires.

Not sure what you mean by "Are they allocated?" Do you mean declared in the struct?
Yes they are being set in the function, as I know BJDebug is my friend :) so I know they are set at the end of the function but after it , they are null.
 

inevit4ble

Well-Known Member
Reaction score
38
OK PROBLEM SOLVED

Basically the unit search in the Index struct wasn't working properly. Some changes made and now everything works and is much Much faster

Thanks for your time guys :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top