Trying to figure this out.
whycali
Member, PRO Posts: 87
GS community I am trying to figure this small part out but keep running in circles.
My Hero actor collects coins in game play but if he dies before finishing the level and starting over how do I subtract the coins he gained. I know its something easy I just can't put a finger on it. Thanks for your help in this matter.
-WhyCali
Comments
Create a self integer attribute in your hero actor , coinscollected.
then when the scene resets , the self attribute will reset to 0 , and the coins will reset to its original value.
You can apply the same concept with game attributes instead of self attribute but you will have to reset the value on each scene.
@Icebox Thank you for the quick response so I have built it the way you stated but sometimes it doesnt remove all the "Coins" I am left sometimes with 1 remaining. Is there something i am missing?
Just to make sure i tried Integer and Index just to see if it made a difference which it did not
Do you actually need to subtract the coins or can you just change the value to zero? If you just need the number of coins to reset to zero each time the game starts, change attribute game.coinsCollected (or self.coinsCollected) to 0 when you start a new game.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang Well right now if i dont subtract and die the "coins" reapear and they can keep getting more and more. I dont want someone to just get coins die get coins die and then be able to "Level up" so subtracting was the only way i thought of the keep the player honest lol
I just don't understand why i get a rogue number when its simple math lol. like if i collect 7 coins and die it should remove the 7 coins but sometimes it will only remove 6 or 5.
Right, I understand but I guess what I'm asking is... do you want the coins to reset to zero each time the player starts a new game? If so, you don't need to subtract anything... you just need to change the value to zero.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Oh gotcha. Well the game starts with 125 coins and as you collect and finish the level you will get to keep said coins. and then the next level you might have 186 coins but if you die i want you to start the second level with 186. what ever you had when you started the level. I hope thats more clear.
Okay, sorry, then @Icebox's suggestion makes the most sense. Why you're ending up with 1 instead of 0 is a mystery. You may need to post a screenshot of your exact rules.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok so i have just took screen shots. Under "When die" its game.rice - self.riceLevel
Rice = Coins just as an FYI
could it be due to using a Self Attribute and a Game Attribute? like you cant mix the two.
Nope, there's not problem with doing that. I would stick a Log Debugging Statement right above the Change Attribute behavior in the "death by contact" rule and put game.rice and self.rice in the expression editor. You can do that this way: game.rice.."/"..self.rice. Then, open the Debugger window while you preview the scene and see what happens. It's hard to give further advice without seeing more of your rules but that may shed some light on what those values are in different situations.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang attached is screen shot of what i put in. is it correct?
So when setting up like that i get an error.
Log(Actor: Character): Invalid Expression. When i get that error there is still one "coin" that didnt delete.
You forgot the separators: ..
Try this:
game.rice.."/"..self.riceCollect
Also be sure you're selecting the attributes from the browser/menu rather than just typing their names in.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang I would firstly like to thank you for helping me out today. After running the log i found that i had the counter and destroy in the wrong area and it would end up not counting on item and then would had on it. That being said THANK YOU SO MUCH!! @Icebox I would like to say thank you as well as you got me in the correct direction and just put it in the wrong spot.
-WhyCali
You're welcome! Glad you figured it out.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User