HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Weird loop problem that must have a simple answer behind...

02-09-2009, 03:38 PM#1
Flame_Phoenix
Hi guys, this is the second post I make about this system. Well, as some of you may know, I am making a small system for my project that will allow the user to pick races in a fashion and cool way. This system uses trackables and destructibles as icons.
In the following code (that looks big, but it is not, more than 50% of it are debug messages and comments. Yes I like comments.) everything works fine except the "call CreateIcon" function. I don't get why it is only called 1 time. It doesn't even make sense because I have a line before it that runs everytime in the loop, just as it should. This bug freaks me off, I even think it make be a problem from JASS or vJASS and not my fault... Anyway, if it is my fault than I am sure it is something really basic ... I usually miss basic stuff =P

Anyway, you people know how the system works in wc3c, +rep and credits for those who help me.

Collapse Stupid piece of code lol:
//===========================================================================
//This trigger creates a complete user interface using trackables and icons
//that allows the player to choose his race on a cool way. When the mouse 
//moves over an icon (with trackable under it) information about the race is
//displayed and when the player clicks the icon, the cameras will move to his 
//spawn position and give him the starting units for his race so the game can
//begin.
//
//Requires Table
//
//@author Flame_Phoenix 
//
//@version 1.0
//===========================================================================
scope SetIcons initializer Init
//===========================================================================
//=============================SETUP START===================================
//===========================================================================
    globals
        //trackables
        private constant string TRACK_MODEL = "war3mapImported\\IconBase.mdl"
        private constant real DOWN_LEFT_Y = -7900.
        private constant real DOWN_LEFT_X = -8000.
        private constant integer COL_NUM = 3
        private constant integer LINE_NUM = 2
        private constant real TRACK_SIZE = 90.
        
        //icons and borders
        private constant integer CHAOS_ORC_ICON = 'B000'
        private constant integer HUMAN_ICON = 'B001'
        private constant integer ORC_ICON = 'B002'
        private constant integer UNDEAD_ICON = 'B003'
        private constant integer NIGHT_ELF_ICON = 'B004'
        private constant integer HIGH_ELF_ICON = 'B005'
        private constant real ICON_SCALE = .5
    endglobals
//===========================================================================
//=============================SETUP END=====================================
//===========================================================================
    globals
        private HandleTable activeTable //your private Table's global variable
    endglobals
    
    private struct aTrackable
        real x
        real y
        real facing
        string modelPath
        integer value
        trackable tc
        
        static method create takes string path, real tx, real ty, real tfacing, integer tvalue returns aTrackable
            local aTrackable data = aTrackable.allocate()
            
            set data.x = tx
            set data.y = ty
            set data.facing = tfacing
            set data.modelPath = path
            set data.value = tvalue
            set data.tc = CreateTrackable(data.modelPath, data.x, data.y, data.facing)
            
            //I assume a trackable has an handle adress just like eveything else
            //and so I use it to refer to it inside table
            set activeTable[data.tc] = data 
            
            return data
        endmethod
    endstruct
//===========================================================================
    private function CreateIcon takes integer value, real x, real y returns nothing
        call BJDebugMsg("value = " + I2S(value))
        
        if value == 0 then
            call BJDebugMsg("Icon created " + I2S(value))
            call CreateDestructable(HUMAN_ICON, x, y, 180, ICON_SCALE, 1)
        elseif value == 1 then
            call BJDebugMsg("Icon created " + I2S(value))
            call CreateDestructable(ORC_ICON, x, y, 180, ICON_SCALE, 1)
        elseif value == 2 then
            call BJDebugMsg("Icon created " + I2S(value))
            call CreateDestructable(UNDEAD_ICON, x, y, 180, ICON_SCALE, 1)
        elseif value == 3 then
            call BJDebugMsg("Icon created " + I2S(value))
            call CreateDestructable(NIGHT_ELF_ICON, x, y, 180, ICON_SCALE, 1)
        elseif value == 4 then
            call BJDebugMsg("Icon created " + I2S(value))
            call CreateDestructable(HIGH_ELF_ICON, x, y, 180, ICON_SCALE, 1)
        elseif value == 5 then
            call BJDebugMsg("Icon created " + I2S(value))
            call CreateDestructable(CHAOS_ORC_ICON, x, y, 180, ICON_SCALE, 1)
        endif
    endfunction
//===========================================================================
    private function TrackableHit takes nothing returns nothing
        //it is safe to not use the group trick because we are sure that
        //all created trackables are in the table
        local aTrackable data = activeTable[GetTriggeringTrackable()] 
        
        if data.value == 0 then
            call BJDebugMsg("Building Human base!")
        elseif data.value == 1 then
            call BJDebugMsg("Building Orc base!")
        elseif data.value == 2 then
            call BJDebugMsg("Building Undead base!")
        elseif data.value == 3 then
            call BJDebugMsg("Building Night Elf base!")
        elseif data.value == 4 then
            call BJDebugMsg("Building High Elf base!")
        elseif data.value == 5 then
            call BJDebugMsg("Building Chaos Orc base!")
        endif
        
    endfunction
//===========================================================================
    private function TrackableTrack takes nothing returns nothing
        //it is safe to not use the group trick because we are sure that
        //all created trackables are in the table
        local aTrackable data = activeTable[GetTriggeringTrackable()] 
        
        if data.value == 0 then
            call BJDebugMsg("Humans!")
        elseif data.value == 1 then
            call BJDebugMsg("Orcs!")
        elseif data.value == 2 then
            call BJDebugMsg("Undead!")
        elseif data.value == 3 then
            call BJDebugMsg("Night Elfs!")
        elseif data.value == 4 then
            call BJDebugMsg("High Elfs!")
        elseif data.value == 5 then
            call BJDebugMsg("Chaos Orcs!")
        endif
    endfunction
//===========================================================================
    private function Actions takes nothing returns nothing
        local aTrackable data
        
        //create the triggers for the trackables
        local trigger hit = CreateTrigger()
        local trigger track = CreateTrigger()
    
        local real prevX
        local integer i = 0
        local real x
        local real y = DOWN_LEFT_Y
        local real maxY = DOWN_LEFT_Y + (TRACK_SIZE * LINE_NUM)
        local real maxX = DOWN_LEFT_X + (TRACK_SIZE * COL_NUM)
        
        //we create the tracktables for the race icons
        loop
            exitwhen y > maxY - TRACK_SIZE
            set x = DOWN_LEFT_X
            
            loop
                exitwhen x > maxX - TRACK_SIZE
                
                //we create the trackable and place the race icon above it 
                set data = aTrackable.create(TRACK_MODEL, x, y, 0, i)    //line that runs perfectly
                call CreateIcon(i, x, y)    //line that is stupid ...
                
                call TriggerRegisterTrackableTrackEvent(track, data.tc)
                call TriggerRegisterTrackableHitEvent(hit, data.tc)

                set i = i + 1
                set x = x + TRACK_SIZE
            endloop

            set y = y + TRACK_SIZE
        endloop
        
        //add the actions for the triggers previously craeted
        call TriggerAddAction(hit, function TrackableHit)
        call TriggerAddAction(track, function TrackableTrack)
    endfunction
//===========================================================================
    private function Init takes nothing returns nothing
        local trigger SetIconsTrg = CreateTrigger(  )
        call TriggerRegisterTimerEvent(SetIconsTrg, 0.5, false )
        call TriggerAddAction(SetIconsTrg, function Actions )
        
        //setting our globals
        set activeTable = HandleTable.create() //Create our spell's private Table for casters
    endfunction
endscope
02-10-2009, 10:46 PM#2
Anitarf
So, what, none of the debug messages in the createIcon function are displayed? Did you also put debug messages before and after you call CreateIcon?
02-11-2009, 07:24 AM#3
Pyrogasm
So it's not creating the icons? Try using 0 instead of 1 as the last argument; it could be that destructable variations start at 0.
02-11-2009, 08:02 AM#4
Flame_Phoenix
Sorry about this, the problem is solved. Somehow, the problem was fixed when I disabled (by placing as a comment) and then enabled again the code line that works well. I did no changes to the code but after that it started working.
This is the most weird thing I've ever seen in JASS.
Anyway, +rep for replying(as long as wc3 allows me to give rep, you guys will get it).