Code Has a strange bug

emootootoo

Top Banana
Reaction score
51
So basically the trigger loops through all the units with the QuestGiver ability on the map, and sets up their structs. It also makes the TalkToMeGREY.mdx model above the units head.

It works fine, besides the fact that one unit never gets the model above its head. I made text tags to show me the order in which the units are looped through, and depending on how many units with the ability are on the map, the number in the order of which the unit does not get the effect over its head changes.

I have absolutely no idea why one unit that isn't even at the start or end of the loop does not get the effect over its head. Oh and yes, the unit that doesn't get the effect over its head does get the text tag, which means it SHOULD be creating an effect, but it doesn't!

Any idea what is going on here?

JASS:
struct QuestData
    integer array count[7]
    integer array count2[7]
    integer array count3[7]
    //-----------------------
    integer array status[7]
    effect array sfx[7]
    boolean array avail[7]
    integer level
    boolean chain
endstruct

function Trig_Quests_Init_Actions takes nothing returns nothing
    local QuestData d
    local group g=CreateGroup()
    local unit u
    local integer i=7
    local string s=" "
    local integer poo=0
    call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea,null)
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        if GetUnitAbilityLevel(u,'A014')>0 then
            set poo=poo+1
            call CreateTextTagLocBJ(I2S(poo),GetUnitLoc(u),0,50,255,255,255,100) // use this to show you the number of quest giver
            set d=QuestData.create()
            call SetUnitUserData(u,d)
            loop
            exitwhen i<0
                if GetLocalPlayer()==Player(i) then
                    set s="TalkToMeGREY.mdx"
                endif
                set d.sfx<i>=AddSpecialEffectTarget(s,u,&quot;overhead&quot;)
                if GetLocalPlayer()==Player(i) then
                    set s=&quot; &quot;
                endif
                set i=i-1
            endloop
        set i=7
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
    set s=null
endfunction

//===========================================================================
function InitTrig_Quests_Init takes nothing returns nothing
    set gg_trg_Quests_Init = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Quests_Init, 0.00 )
    call TriggerAddAction( gg_trg_Quests_Init, function Trig_Quests_Init_Actions )
endfunction</i>
 

emootootoo

Top Banana
Reaction score
51
Yes.. all the units in the loop that get the effect attached to them are the exact same unit with the exact same properties. It's just stupid, it should work.

I've made a temporary fix by finding out the number of the unit that doesn't work and not removing the unit from the group if it is that number, sp it does that unit twice therefore creating the effect.

But I want a permenant solution so there is no need to have to check the number of the picked unit every time you add a few more of the units to the map. (because this should actually not be happening)
 

Vexorian

Why no custom sig?
Reaction score
187
Yes.. all the units in the loop that get the effect attached to them are the exact same unit with the exact same properties. It's just stupid, it should work.

I've made a temporary fix by finding out the number of the unit that doesn't work and not removing the unit from the group if it is that number, sp it does that unit twice therefore creating the effect.

But I want a permenant solution so there is no need to have to check the number of the picked unit every time you add a few more of the units to the map. (because this should actually not be happening)

My bet is, you are missing with string ids too much:

JASS:

function AddSpecialEffectTargetPlayer takes player p, string fx, unit u, string attach returns effect
    if(GetLocalPlayer==p) then
        return AddSpecialEffectTarget(fx,u,attach)
    endif
 return AddSpecialEffectTarget(&quot;&quot;,u,attach)
endfunction


function Trig_Quests_Init_Actions takes nothing returns nothing
    local QuestData d
    local group g=CreateGroup()
    local unit u
    local integer i=7

    local integer poo=0
    call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea,null) //must use a global group and a TRUE boolexpr instead of null
    loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        if GetUnitAbilityLevel(u,&#039;A014&#039;)&gt;0 then
            set poo=poo+1
            call CreateTextTagLocBJ(I2S(poo),GetUnitLoc(u),0,50,255,255,255,100) // use this to show you the number of quest giver
            set d=QuestData.create()
            call SetUnitUserData(u,d)
            loop
                exitwhen i&lt;0
                set d.sfx<i>=AddSpecialEffectTargetPlayer(Player(i),&quot;TalkToMegrey.mdl&quot;,u,&quot;overhead&quot;)
                set i=i-1
            endloop
            set i=7
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
    set s=null
endfunction

</i>
 

emootootoo

Top Banana
Reaction score
51
Thanks for the help, however:

Using the method shown in your post Vexorian, the same bug occurred. However, I placed more of the units on the map, and then all of them got the effect, but an effect that previously worked (from another trigger) didn't show up anymore. So I used your method on that one aswell, and it did not fix it.

So basically, with your method or mine, in both occasions it is impossible for me not to have one unit missing an effect. This is very strange so I guess I'll have to live with it.

Edit: K this bug only affects player 1. All the other players are fine. What's up with that?
Edit2: OK, I think I fixed it by making the loop start at 8 and exit at <1... So yeah, I fixed a problem that shouldn't have existed by doing something that shouldn't have fixed any problems. Awesome! (oh yeah and i had to do i-1 for any player things obviously)

Final thoughts: 0 index of an array is buggy
 

Vexorian

Why no custom sig?
Reaction score
187
Thanks for the help, however:

Using the method shown in your post Vexorian, the same bug occurred. However, I placed more of the units on the map, and then all of them got the effect, but an effect that previously worked (from another trigger) didn't show up anymore. So I used your method on that one aswell, and it did not fix it.

So basically, with your method or mine, in both occasions it is impossible for me not to have one unit missing an effect. This is very strange so I guess I'll have to live with it.

Edit: K this bug only affects player 1. All the other players are fine. What's up with that?
Edit2: OK, I think I fixed it by making the loop start at 8 and exit at <1... So yeah, I fixed a problem that shouldn't have existed by doing something that shouldn't have fixed any problems. Awesome! (oh yeah and i had to do i-1 for any player things obviously)

Final thoughts: 0 index of an array is buggy


That's is basically a wrong conclusion that makes no sense.

Edit: want to know what really happened? you are using size 7 arrays in your struct when you needed size 8 arrays...
 

emootootoo

Top Banana
Reaction score
51
OK, I admit I have not had any problems with 0 index before, however, for this specific situation not using them, magically fixed my problem entirely.

OK, I see I needed size 8 arrays, but player 1 was being referred to all indexes of 0, I never tested with player 8. So I'm not quite catching onto why not having the array size big enough would screw that up? I mean only one unit didn't get the effect and it was for player 1 who used the 0 index. Does not being able to set the 7th value of an array effect the 0th value? But that still doesn't explain why it worked for 60 out of 61 units or 3 out of 4 units..
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top