Jump to content

how is this even possible? logging a sprite only if onAir == true but the log says its false


Recommended Posts

in my newest game i'm having serious troubles ..  it's the first time that i have absolutely no clue why things happen the way they happen



the biggest problem is that the game works as expected but after 3 to 10 minutes things suddenly happen that should not happen.. i did not program those things..  i went over my code a hundred times now :(


my sprites that are constantly killed and reset suddenly are killed right after the reset.. but the reset sets a custom object variable to true and therefore should block the killing (but it doesn't)


it's no complex thing..  if (var == true) {do not kill !!!!!!}  (but it's killed anyway)


this is probably related to what i just observed.


i wrote the following code in my kill function in order to find out more about those weird problems:

 if (obj.sprite.onAir === true){console.log(obj.sprite); return;}

the interesting thing is that if i look at chromes console log the sprite definitely says " onAir = false "  

if it really were false it shouldn't be in the log .. right ??? what the hell?


(using phaser 2.3)



Link to comment
Share on other sites

thx for your reply :)

do you think that something changed the value right between the if statement and the console.log() ??     i'm definitely going to investigate that.....




there are only 2 places where i set onAir to true..    the "exploding" function that sets onAir to true but sets it back to false after a tween and right before it calls the kill function

(so objects passed to the kill function from here should never be "onAir" )


an the reset function which is called every second ...  so this one falls out of the "linear" concept.. it suddenly kicks in and could interfere in very VERY rare cases..   


im going over my "reset function" again..  there has to be a logical reason for that ..   :angry:

Link to comment
Share on other sites

I ever had this kind of problem with console.log(object).


That's definitly what qdrj said.


If you're loggin an object, then when you go through its parameters, the values are the CURRENT ones of the object, not the ones that were set when you logged it.


To be clear:

player.alive = true;


player.alive = false;


=> Check in console: player.alive is false.


I don't know if it's browser related but now I use "debugger;" or breakpoint.

Link to comment
Share on other sites

thank you both..  after inspecting the reset function that is called every second i found a way how this could interfere with the kill function i wrote and removed that rare case..  the game is now running properly and the weird behaviour is gone..  only one problem left though..  the game is getting slower over time.. but this is a topic for a different thread :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...