HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

why this doesn't happen BUG (simple but I cant see) ??

08-02-2008, 05:33 PM#1
Flame_Phoenix
Hi guys, I am nearly in the end of the code for CBS, and there is a chance I will remake everything to be easier for people to understand. However, before doing anything, I need to fix this stupid bug I have, and that I don't know why it happens.
This is the thing: I have 1 unit variable array called udg_ReturnUnits.
every time I select one of this units (or more because they are very close, and so the player can click one of the by accident) I want to execute a function called "Clear()" which will destroy the interface and null everything, put cameras back to normal and pan the camera to the user.

Collapse JASS:
//here we check if he clicked unit was to one of the units that would allow the player
    //to exit the bag    
    set i = 0
    loop
        exitwhen(i == 7)
        if (selected == udg_ReturnUnits[i]) then 
            call BJDebugMsg("exit")
            call Clear()
        endif
        set i = i + 1
    endloop

Problem is that, although the "exit" message always appears, the Clear function is NOT always executed and I don't know why .. Happens that, unfortunately I have to click several times on it to work ... Can some one tell me why this happens ?

+rep given ofc.

Btw, because I am so proud of what I've accomplished so far, here is CBS. Please note it is NOT complete yet, and it has some flaws (like placing the bag inside of itself lol) that I intend to fix.
Hope you all like it =)
Attached Files
File type: w3xCBS.w3x (262.8 KB)
08-02-2008, 05:44 PM#2
Troll-Brain
Did you put a debug message in the function Clear ?
And post this function.
08-02-2008, 06:57 PM#3
Flame_Phoenix
No I didn't, but I am sure it runs well (I think).
This function is a lot more complex.
I will start by explaining the logic. The interface is made of 2 main things:
- The destructibles that are the icon, they can't be selected and they are saved in a variable called udg_InterfaceIcons with 66 slots.
- The dummy units behind the destructibles, these units have a special model and can be clicked. Things work when we click the units. These are saved in a variable called udg_ClickUnits with 66 slots as well.

Why 66 slots ?? Well, CBS takes up to 60 items. We have 66, the first 60 are for the bag, the other 6 are for the User's Inventory.
Then we have the return units, that I already explained in the post before.
When making clear will them all and we null them all, that's easy. The interface is destroyed.

Then we have onWorking variables, these variables save information about where the player clicks. This part works by pairs of two. This means that we let the player click 1 unit, and we only take action when he clicks a second unit, thus making a pair.Such variables are:
- udg_ClickedNumber -> this saves the number of the first clicked unit.
- udg_ClickUnit -> this is an array of 2 slots. The first slot saves the unit we clicked the first time (if I remember correctly) and the second saves another unit with an effect model. This effect model is created upon the first selected unit.
- udg_ImageDescription -> this is the destructible that appears amplified when we select a unit.
- udg_ItemInterfaceText ->this is the floating text that appears describing the clicked item. The clicked item is always the first item of the pair, and is ofc, the item amplified.

I think this is what you people need to know, everything else is in the map I posted above. I just hope it helps you all helping me xD.

This system uses a very simple logic. I believe most of you could do it, still it has problems as everything else.

Collapse JASS:
//This Clears and nulls everything
function Clear takes nothing returns nothing
    local integer j //a counter for our loops
    local item anItem = null
    
    set j = 0
    loop
        exitwhen(j == 66)
        
        //here we kill the units behind them
        call KillUnit(udg_ClickUnits[j])
        set udg_ClickUnits[j] = null
        
        //here will kill the Icons, we no longer need them
        call KillDestructable(udg_InterfaceIcons[j])
        set udg_InterfaceIcons[j] = null
                
        //here we also remove the Return Units
        if(j <= 7) then
            call KillUnit(udg_ReturnUnits[j])
        endif
        
        set j = j + 1
    endloop
    
    //we reset the clcking variables in order to prevent further bugs when 
    //we use it for the second time
    set udg_ClickedNumber = -1
    set udg_ClickedUnit[0] = null
    call KillUnit(udg_ClickedUnit[1])
    set udg_ClickedUnit[1] = null
    
    //we get rid of the texttag!
    call DestroyTextTag(udg_ItemInterfaceText)
    set udg_ItemInterfaceText = null
    
    //Here we kill the amplified description image icon
    call KillDestructable(udg_ImageDescription)
    set udg_ImageDescription = null
    
    //here we take away the items from the caster and hide them
    set j = 0
    loop
        exitwhen(j == 6)
        set anItem = UnitItemInSlot(udg_User, j)
        call UnitRemoveItem(udg_User, anItem)
        call SetItemVisible(anItem, false)
        set j = j + 1
    endloop
            
    //now we add the new Items to the caster
    //in every null spot we add a dummy item to take up some space, so the real
    //Items can be in the spot the user choosed for them when in the Interface
    set j = 60
    loop
        exitwhen(j == 66)
        if (udg_BagPack[j] == null) then
            set anItem = CreateItem(dummyItemId(), GetUnitX(udg_User), GetUnitY(udg_User))
            call UnitAddItem(udg_User, anItem)
        endif
        call UnitAddItem(udg_User, udg_BagPack[j])
        set j = j + 1
    endloop
            
    //now we remove the dummyItems because they are no longer required
    set j = 0
    loop
        exitwhen(j == 6)
        if (GetItemTypeId(UnitItemInSlot(udg_User, j)) == dummyItemId()) then
            call RemoveItem(UnitItemInSlot(udg_User, j))
        endif
        set j = j + 1
    endloop
    
    //here we unpause the caster and make him vulnerable
    //so the game is able to continue
    call PauseUnit(udg_User, false)
    call SetUnitInvulnerable(udg_User, false)
    call ResetToGameCamera(0.0)
            
    //turn off anti-scroll trigger
    
    //kill the filter
    call DisplayCineFilter(false)
    call EnableUserUI(true)
    
    //reseting camera bounds as in the beggining of the map
    call SetCameraBounds(GetRectMinX(bj_mapInitialCameraBounds), GetRectMinY(bj_mapInitialCameraBounds), GetRectMinX(bj_mapInitialCameraBounds), GetRectMaxY(bj_mapInitialCameraBounds), GetRectMaxX(bj_mapInitialCameraBounds), GetRectMaxY(bj_mapInitialCameraBounds), GetRectMaxX(bj_mapInitialCameraBounds), GetRectMinY(bj_mapInitialCameraBounds))
    
    //now we Pan the camera to the position of the user
    call PanCameraToTimed(GetUnitX(udg_User), GetUnitY(udg_User), 0.0)
    
    //cleaning more mess
    set udg_User = null
endfunction
08-02-2008, 07:23 PM#4
darkwulfv
Didn't you just make this same exact post in the other thread you started?
08-02-2008, 07:41 PM#5
Flame_Phoenix
Quote:
Didn't you just make this same exact post in the other thread you started?
LOl, yes it was mistake, thx for Troll-Brain for PM me about it.
+rep =P

S, can you guys help me ?
08-02-2008, 08:32 PM#6
Pytho
Quote:
Originally Posted by Flame_Phoenix
S, can you guys help me ?
Here's (finally) the point where you have to learn to help yourself.

This function is as you said long and complex, so for god's sake just add some DebugMessages as enough people have told you allready on various occasions. Than you can track the error and think about what might have gone wrong. And if you don't find it out, post the problem and where you think the error is. The board exists so people help each other, but it's not working the way you submit something you have problems with and let others do the work you could do yourself. (beside: If others allways help you with the harder things you won't learn anything)
08-02-2008, 09:08 PM#7
darkwulfv
BJDebugMsg is your FRIEND. Put one after every key point, and when you notice one missing, you've narrowed it down. Once you've found the problem code section, try to fix it. And if it doesn't work, THEN you can ask us. Because honestly, giving us massive hunks of code and saying "fix plox" doesn't help us. We need specific areas to look at.
08-02-2008, 09:58 PM#8
Malf
Because using an array with an index of 0 is wrong. Correct me if I'm mistaken, I may have forgotten.
08-02-2008, 10:19 PM#9
Flame_Phoenix
Guys Guys Guys !!! I am BJDEbugggMesg !! Just look at my first post ! By using it I found out that the problem was in Clear() function, but that's the far I can go !

If I can do things myself I do them, because it does save a lot of time, this is my last resort !

And all arrays start on 0, that's default ...

So, instead of trying to kill me , can you actually know something I don't, that's causing this error ?
08-02-2008, 10:29 PM#10
darkwulfv
Put the BJDebugMsg's in the Clear() function itself...
08-03-2008, 10:54 AM#11
Flame_Phoenix
Ok, after intensive testing, I found the reason of my suffering ... but I really don't understand why it happens ...
Here it is, the code is well commented and explained, hope you all like it.

Collapse JASS:
//This Clears and nulls everything
function Clear takes nothing returns nothing
    local integer j //a counter for our loops
    local item anItem = null
    
    set j = 0
    loop
        exitwhen(j == 66)
        
        //here we kill the units behind them
        call KillUnit(udg_ClickUnits[j])
        set udg_ClickUnits[j] = null
        
        //here will kill the Icons, we no longer need them
        call KillDestructable(udg_InterfaceIcons[j])
        set udg_InterfaceIcons[j] = null
                
        //here we also remove the Return Units
        if(j < 7) then
            call KillUnit(udg_ReturnUnits[j])
        endif
        
        set j = j + 1
    endloop
    
    //we reset the clcking variables in order to prevent further bugs when 
    //we use it for the second time
    set udg_ClickedNumber = -1
    set udg_ClickedUnit[0] = null
    call KillUnit(udg_ClickedUnit[1])
    set udg_ClickedUnit[1] = null
    
    //we get rid of the texttag!
    call DestroyTextTag(udg_ItemInterfaceText)
    set udg_ItemInterfaceText = null
    
    //Here we kill the amplified description image icon
    call KillDestructable(udg_ImageDescription)
    set udg_ImageDescription = null
    
    //here we take away the items from the caster and hide them
    set j = 0
    loop
        exitwhen(j == 6)
        set anItem = UnitItemInSlot(udg_User, j)
        call UnitRemoveItem(udg_User, anItem)
        call SetItemVisible(anItem, false)
        set j = j + 1
    endloop
            
    //now we add the new Items to the caster
    //in every null spot we add a dummy item to take up some space, so the real
    //Items can be in the spot the user choosed for them when in the Interface
    set j = 60
    loop
        exitwhen(j == 66)
        if (udg_BagPack[j] == null) then
            set anItem = CreateItem(dummyItemId(), GetUnitX(udg_User), GetUnitY(udg_User))
            call UnitAddItem(udg_User, anItem)
        endif
        call UnitAddItem(udg_User, udg_BagPack[j])
        set j = j + 1
    endloop
            
    //now we remove the dummyItems because they are no longer required
    set j = 0
    loop
        exitwhen(j == 6)
        if (GetItemTypeId(UnitItemInSlot(udg_User, j)) == dummyItemId()) then
            call RemoveItem(UnitItemInSlot(udg_User, j))
        endif
        set j = j + 1
    endloop
    
    //here we unpause the caster and make him vulnerable
    //so the game is able to continue
    
//=================BUG !!! EVERYTHING BAG HAPPENS WHEN i UNPAUSE THE CASTER, WHY !
//    call PauseUnit(udg_User, false)
//=================BUG !!!========================================================

    call SetUnitInvulnerable(udg_User, false)
    call ResetToGameCamera(0.0)
            
    //turn off anti-scroll trigger
    
    //kill the filter
    call DisplayCineFilter(false)
    call EnableUserUI(true)
    
    //reseting camera bounds as in the beggining of the map
    call SetCameraBounds(GetRectMinX(bj_mapInitialCameraBounds), GetRectMinY(bj_mapInitialCameraBounds), GetRectMinX(bj_mapInitialCameraBounds), GetRectMaxY(bj_mapInitialCameraBounds), GetRectMaxX(bj_mapInitialCameraBounds), GetRectMaxY(bj_mapInitialCameraBounds), GetRectMaxX(bj_mapInitialCameraBounds), GetRectMinY(bj_mapInitialCameraBounds))
    
    //now we Pan the camera to the position of the user
    call PanCameraToTimed(GetUnitX(udg_User), GetUnitY(udg_User), 0.0)
    
    //cleaning more mess
    set udg_User = null
    set udg_isItClear = false
endfunction

Can some one explain me the reason why this is causing the bug ?
As you can see I pause the caster and make him invulnerable when he uses the spell.
In the end, it is obvious I must make him vulnerable and unpause him ... but it looks I can't unpause the caster without creating bugs ... This is really bad .. people will want to use their heroes after using the bag xD
08-03-2008, 10:56 AM#12
darkwulfv
I'm not seeing where he's paused to begin with, so... Unless it's in a different trigger. (Which it probably is, since this is the Clear() function.)
08-03-2008, 11:09 AM#13
Flame_Phoenix
The caster is paused in another function called Create()
Create() function is responsible (like the name says) to create the user interface. It creates the Destructible rows and the units. In that function we pause the caster and make him invulnerable. Create() function also uses another auxiliary function called setCamera() which is responsible, like the name says, to set the cameras correctly.

I also see no reason for the bug, but truth is that it happens.
This is something bad I have to fix no matter what ...
If you don't believe me, test the map yourself, it is attached to this post. Try enabling that line of code, than compile it and run the test. You will be lucky if the "exit" message doesn't appear more than once.
Attached Files
File type: w3xCBS.w3x (580.8 KB)
08-03-2008, 05:35 PM#14
ToukoAozaki
Considering the code is not being executed, I suspect two possible causes.

1. Handle variable bug. You might be passing unassigned variables to natives, in consequence the thread crashes and stops its execution.
2. Op limit. You might be hitting the op limit by unproperly designed loops.

I think #1 is a likely cause, as you only seem to get trouble with single call in function Clear.

Edit: BTW, does this code even compile? I'm getting errors at sized array part.
08-03-2008, 06:55 PM#15
Anitarf
Quote:
Originally Posted by Flame_Phoenix
Can some one explain me the reason why this is causing the bug ?
Can you explain what the bug is? Do the actions after this one not run? Does the unit disappear? Do pink unicorns start flying all across the map? What?