Changing An Attribute When Something Doesn't Happen??
theJudoguy
Member Posts: 7
I'm creating a pool type a game and I'm stuck on how to subtract a life when the white ball doesn't hit another ball. Any help on this would be great!
Thanks.
Comments
I would set up an boolean attribute called "white_ball_miss" either Game of Scene level.
rule
if scene.white_ball_miss = true
do change attribute lifes to lifes -1
You would also need a rule to turn white_ball_miss back to false before every shot.
@ManxMann -- that still doesn't help to figure out the game that the player didn't hit.
@theJudoguy -- you probably have a rule set up to manage what happens when you DO hit another ball, right? You can simply add subtracting a life to the 'otherwise' section and you're ready to go.
@pHghost - Thanks but I've tried that before and it didn't seem to work! When I previewed it the lives decreased very quickly over a single turn.
See my videos on Gs logic that should help you understand coding.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru - Which video covers this?
For the otherwise section to work properly, you need to check what are the rules that apply to this otherwise.
When are you checking for what to do when the balls hit? Is the game checking for this all the time, or only once the white ball starts moving?
It is hard to give a precise solution when we don't see how you set the logic up. Can you post a screenshot of that rule? It will help a lot.
@pHghost - I have quite a few different rules but the only one of any use here is the "bounce if this actor collides with actor of tag 'ball' ". I'm pretty new to this so what I did was add a rule saying when actor collides with tag 'ball', otherwise: change attribute game.lives to game.lives - 1. This didn't work.
I expect this is wrong or incomplete
How about this?...
This is all assuming to take the shot you have to click on the white ball and pull back to set power and angle.
You will need to set up the following attributes:
scene.Turn - boolean
scene.white_ball_miss - boolean
game.ball_motion - real (you would need to constrain this to the speed/any motion of the actor white ball)
game.lifes - integer
Set the following up rules in actor White Ball
Rule 1
touch is: Pressed
do change attribute scene.Turn to True
Rule 2
Actor overlaps or collides with: actor with tag "BALL"
do change attribute scene.white_ball_miss to True
else change attribute scene.white_ball_miss to False
Rule 3 (set to all)
if game.ball_motion = 0
if scene.white_ball_miss = true
if scene.Turn = true
do change attribute game.lifes to game.lifes - 1
change attribute scene.Turn to False
else change attribute scene.Turn to False
@theJudoguy
@theJudoguy -- here is an example you can download of how the rules could work.
In my example you get three points for a hit and lose one for a miss. Click the ball for it to rotate, it will shoot in the direction of the arrow when you let go.
Have a look at how the rules are set up for inspiration.
The project is a little different than yours, but that's so you have to do a little work to adapt it.
GS logic series.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@ManxMann - Thanks that's seemed to have a worked!
@pHghost - Thanks for all your help as well!