How to subtract a value from integer?

Slayre77Slayre77 Member, PRO Posts: 115
Silly question I know but then again Im not good at GS :P

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    Use 'minus' (-).
  • Slayre77Slayre77 Member, PRO Posts: 115
    @Socks I tried! I have two actors coming at each other from either side of the screen, when they touch they will minus 1 HP so I put If one touches the other, Change Attribute self.HP to -1 is that correct? because it doesnt work. I already set that if self.HP is 0, destroy actor but it DOESNT work!
  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2013
    . . . . If one touches the other, Change Attribute self.HP to -1 is that correct? . . .

    Change Attribute self.HP to -1 will mean that when the actors collide your HP value will be changed to -1. (eg: Start out with a HP value of 7, then collide, HP is now -1 . . . or . . . start out with a HP value of 99, then collide, HP is now -1)


    Change Attribute self.HP to self.HP-1 will mean that when the actors collide your HP value will go down by 1. (eg: Start out with a HP value of 7, then collide, HP is now 6 . . . or . . . start out with a HP value of 99, then collide, HP is now 98)


    If your destroy condition is looking out for a value of 0 but only ever receives -1 it will never trigger.
  • Slayre77Slayre77 Member, PRO Posts: 115
    @Socks Thanks :D
  • Slayre77Slayre77 Member, PRO Posts: 115
    But for some reason it doesnt work... The attribute HP should be in the actor or in the game?
  • SocksSocks London, UK.Member Posts: 12,822
    But for some reason it doesnt work... The attribute HP should be in the actor or in the game?
    You can keep it where you like, it could be a game attribute or an actor attribute (or even a scene attribute) - but I think for this kind of thing making it a game attribute is probably the most flexible.

  • Slayre77Slayre77 Member, PRO Posts: 115
    For some reason it doesnt work! The behaviours are like if Red and Blue collide, turn boolean BlueDamaged1 to true on the Red actor, and vice versa (I did it this way so that when I have mor enemies in the future I can just use the boolean for its attack) . So when BlueDamaged1 is true, then change attribute HP to HP-1. i dont see what is wrong there but it doesnt work !!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @Slayre77 by the sound of it you're best to have the HP attribute as a scene attribute. Suggestion: check if this attribute HP is integer as it should be....

    Also remember to make the starting value of HP the max. number of points you start off with, otherwise you'll land up with minus numbers...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2013
    ) . . . The behaviours are like if Red and Blue collide, turn boolean BlueDamaged1 to true on the Red actor, and vice versa . . .
    So am I right in thinking that the when the red and blue actors collide then:

    The red actor turns the attribute to true and . . .
    The blue actor turns the attribute to false.

    If this is how you have it set up then I suspect the blue change is cancelling out the red change.

    Or if both are set to return true then your HP would be going down by 2 each time, but this is just guesswork as 'it doesn't work' could mean a million things, anything from the score goes up, to it goes down by the wrong amount, to it reaches 1 and stops (etc) ?
  • Slayre77Slayre77 Member, PRO Posts: 115
    @Socks the blue actor does not turn it to false. Not working as in nothing is happening = actors arent getting destroyed
  • Slayre77Slayre77 Member, PRO Posts: 115
    @gyroscope thanks :)
Sign In or Register to comment.