playMaker

Author Topic: Compare int is behaving weird [SOLVED]  (Read 3233 times)

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Compare int is behaving weird [SOLVED]
« on: November 25, 2012, 06:57:09 AM »
so I'm making a prototype for a school project - so far i have the enemies chasing the player, and when they come close they retract 25 health from the health Int which is then updated with the new health, converted to a string and displayed as a GUI TEXT - all of that works fine, but i now have a listener that has a compare int action that compares the health int to 0, and if it is equal to or below 0 it will go to next state which destroys the player.

The weird part is that it doesn't work. Not just that, but if i set it to compare to 100 (what the player starts with) it works like a charm and instantly kills the player when the game starts. If i set it to 200 it also works (because starting value 100 <= 200)

If i set it to 75 it doesn't work - the health will just go to 75 and below and not kill the player, but if i switch compare from <= to >= it works again (because 100 starting value => 75)

Any ideas as to why it wont compare the int to 0 or 75 for that matter? seems like equals to or less than only works when i set it to more than the starting value of the player health :(
« Last Edit: November 25, 2012, 10:40:31 AM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Compare int is behaving weird
« Reply #1 on: November 25, 2012, 07:09:21 AM »
do you check it every frame? Could you give us a screenshot of your setup?
Best,
Sven

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Compare int is behaving weird
« Reply #2 on: November 25, 2012, 08:14:23 AM »
Here are screenshots of the entire thing:

Player state 1: http://imageshack.us/f/39/player1c.png/
(gets the owner of the FSM and puts it in a GA variable) (this is used for the zombie to track and move towards the player)

Player state 2: http://imageshack.us/f/37/player2c.png/
(goes to listener and waits for health to be = or below 0, where after it should move to state 3 and destroy the player)

Player state 3: http://imageshack.us/f/819/player3t.png/


Health Manager state 1: http://imageshack.us/f/255/healthmanager1.png/
Sets the player's start health of 100 and saves itself in a GA variable (for the zombie to send the damage event when it hits the player)

Health Manager state 2: http://imageshack.us/f/35/hm2yc.png/
Converts current health to a string and displays on the HUD

Health Manager state 3: http://imageshack.us/f/823/healthmanager3.png/
Waits for the zombie to send the retract health transition

Health Manager state 4: http://imageshack.us/f/11/healthmanager4.png/
makes a -25 change to the health int and goes back to state 2 where it updates and displays the new health value, then goes back to listener again


Zombie state 1: http://imageshack.us/f/542/enemy1.png/
the zombie has a trigger around it, so when it reaches the enemy it goes to stage 2. In this stage there is also a tween, making the zombie move slowly towards the player

Zombie state 2: http://imageshack.us/f/100/enemy2.png/
Send event to the Health_Manager to make a -25 change to the player's health int

Zombie state 3: http://imageshack.us/f/9/enemy3.png/
Wait 1.5 secs before you start chasing the target again (this also prevents zombie from doing damage more than once every 1.5 seconds) this is a temporary solution and will be replaced with a zombie hit animation instead


__________________________________________________________________________________________

No i'm not checking every frame, and the health int works fine in itself starting with 100 hp and retracting 25 every time the zombie hits - the problem is in the player state 2 where it compares the int with 0 and it doesnt work even though i can see the int changing to 0 the compare doesn't register it.

It works if i make the compare be 75 and the comparison being above (it will register the hp is 100 which is above 75 and will then successfully destroy the player) but it wont register "equals to" or "below" =(

Any help is greatly appriciated
« Last Edit: November 25, 2012, 08:28:33 AM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Compare int is behaving weird
« Reply #3 on: November 25, 2012, 08:23:07 AM »
the first and second and the fourth and 5th images are the same, so we can't even see your compare ;)
Best,
Sven

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Compare int is behaving weird
« Reply #4 on: November 25, 2012, 08:25:31 AM »
damn, my bad hold on, updating

___________________________

Images updated, thanks for sticking with me :)
« Last Edit: November 25, 2012, 08:29:05 AM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Compare int is behaving weird
« Reply #5 on: November 25, 2012, 08:49:25 AM »
well there we go, try comparing the int every frame. This only checks it once when the game is started. After that, it doesn't care if the values change.
To save performance I would add a global event to the state that compares the int and use a send event action each time he's damaged (there's a dropdown to send event to another FSM).
Best,
Sven

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Compare int is behaving weird
« Reply #6 on: November 25, 2012, 09:59:23 AM »
thanks a ton :) yes that took care of the problem with it not registering changes, thanks so much! :)
Remember, you don't fail unless you give up trying to succeed!