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

[vJASS] Respawn system not working anymore after I added something...

Status
Not open for further replies.
Level 19
Joined
Oct 12, 2007
Messages
1,821
Heya.

Once again I'm in trouble.

I got a respawn system that worked perfect, but since I added some changes to it it doesn't work anymore.

Here's a loop that runs in the system on map init. It indexes every unit so that it can be respawned. During this indexing it saves the unit owner. But since I want to use Player(13) units (Neutral Victim), I have to use a trick.
That's why I wanted to put a check inside the loop to see if the unit type of the picked unit is one of the units i want to become neutral victim. If it is that type it should change its owner to Player(13) right before I save his owner for the indexing.

The thing that is not working atm:
It doesn't respawn units anymore while I only added changes in this init part of the system. It correctly changes the owners of the units ingame to Player(13), but for some reason no single unit gets revived anymore, not even the ones I didn't change the owner of.

This is how it looked like before the change:
JASS:
    call GroupEnumUnitsInRect(G,GetWorldBounds(),Filter(function Filt))
    loop
        set u = FirstOfGroup(G)
        exitwhen u == null
        call GroupRemoveUnit(G,u)
        call RegisterUnitIndex(u)
        call CreateUnitProperties(u)
        set RespawnX[u:Id] = GetUnitX(u)
        set RespawnY[u:Id] = GetUnitY(u)
        set RespawnUnitType[u:Id] = GetUnitTypeId(u)
        set RespawnAngle[u:Id] = GetUnitFacing(u)
        set RespawnP[u:Id] = GetOwningPlayer(u)
    endloop
    call GroupClear(G)

This is how it looks like now: (BeastType[...] are the id's of the unit types that should change. LastBeast is the amount of beasts I added to BeastType[...].
JASS:
    call GroupEnumUnitsInRect(G,GetWorldBounds(),Filter(function Filt))
    loop
        set u = FirstOfGroup(G)
        exitwhen u == null
        call GroupRemoveUnit(G,u)
        call RegisterUnitIndex(u)
        call CreateUnitProperties(u)
        set RespawnX[u:Id] = GetUnitX(u)
        set RespawnY[u:Id] = GetUnitY(u)
        set RespawnUnitType[u:Id] = GetUnitTypeId(u)
        set RespawnAngle[u:Id] = GetUnitFacing(u)
        set i = 0
        loop
            if RespawnUnitType[u:Id] == BeastType[i] then
                call SetUnitOwner(u, Player(13), false)
            endif
            exitwhen LastBeast == i or RespawnUnitType[u:Id] == BeastType[i]
            set i = i + 1
        endloop
        set RespawnP[u:Id] = GetOwningPlayer(u)
    endloop
    call GroupClear(G)
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
It's probably in the respawn trigger itself. Maybe it only fires on Neutral Hostile deaths?

Well even if that was so... Neutral Hostiles also don't respawn anymore.

What I wrote in the first post was all that I changed in this system apart that a few lines above this (in the init part) I have some lines with "set BeastType[...] == 'xxxx''.

This is how the filter looks like: (But as I said, it was already like this)
JASS:
private function Filt takes nothing returns boolean
    local unit u = GetFilterUnit()
    local boolean ok = GetPlayerId(GetOwningPlayer(u)) > 8 and GetUnitTypeId(u)!='nepl'
    set u = null
    return ok
endfunction
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
as I don't know how far "the system" reaches, I will somehow reluctantly ask you: Are functions RegisterUnitIndex and CreateUnitProperties part of the system, followed by the second question: Might the problem be that those functions have changed?

Then, as said, add debugging messages to check whether the actions, or conditions, whichever you use, of the respawning trigger even run.. If so, try to print as much info as possible, also regarding where the actions possible stop or skip things..

Also, a slight improvement might be, especially if you add alot of unit types to "BeastType", you might want to consider saving in a (Hash)Table whether the unit type should become Neutral Victim or not. This gives you, inside the FirstOfGroup-loop an O(1) running time instead of a O(LastBeast) running time..

Furthermore, logically, when for example slots 0,1,2 and 3 of BeastType are occupied, LastBeast would be 4, because the way you describe it, it would basically be the "size" of the (occupied part of the) array. Then, you should increment variable "i" before checking "LastBeast == i". Also, you could just add "exitwhen true" inside the if, instead of using an or on the exitwhen..
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
Well, when I change back and forth between the 2 things I posted the result also changes.
So if I use version 1, my respawns work, but the units aren't owned by Player(13) anymore.
When I edit it again, then the units change owner but the respawn system doesn't want to work.
So RegisterUnitIndex and CreateUnitProperties are part of the system and they haven't changed.

I personally know nothing about hashtables so that's why I did it this way though, but that's not the big problem here now anyway.:D
For the LastBeast integer I also checked how it works with the loop and I did that the right way, and in case that went wrong, only one out of the 31 beast types would be ignored.

It's just weird that it doesn't work.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Bro, I'm going to give you a tip

So RegisterUnitIndex and CreateUnitProperties are part of the system and they haven't changed.

Take those things out of the system. Make unit indexing an entirely separate thing. Make unit properties an entirely separate thing. Make the respawn stuff an entirely separate thing. You should have 3 separate systems. Doing this will simply your code and probably solve your bug in the process.

If the bug is still there, make sure the indexing works, then make sure create properties works, then check various portions of the respawning to make sure they work.

The bigger your system is, the more complicated it becomes, the more cumbersome it becomes, and the harder it becomes to manage (in this case debug). Keep your code as short and as simple as possible. If this means 50 different systems, do 50 different systems. Don't mash them together.
 
Level 19
Joined
Oct 12, 2007
Messages
1,821
But the respawn system needs their ID so how do I make sure that the indexing system runs before the respawn system. They are both at map init.

And I might have been unclear but they are different systems but I ment to say that the respawn system has the other 2 as requirements.
 
Status
Not open for further replies.
Top