about random numbers
whycali
Member, PRO Posts: 87
GS Family I need some help trying to see how to do this. So I have Coins and every Coin = +1 when touch by Hero. I also have special Coin's that come at a random number from (5,25). When the Hero dies I have no issues when I don't use random numbers is there away to keep the random numbers option but also remove them when Hero dies? I hope that was clear.
Thanks
WhyCali
Comments
Sorry after rereading this I meant to say when hero dies I take away the coins they might have gained.
I'm not sure I'm following exactly what you're asking but here are my thoughts. If you want to remove the number of coins your player picked up between deaths, keep track of how many have been picked up in a separate Attribute (like recentCoins). Then when the player dies remove the 'recentCoins' from 'Coins'.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
It's not clear. What do you mean by "remove them"?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you all for getting back to me so fast.
Sorry for not being clear was on a late night maintenance for my real job and was a little scattered. let me try and clear this up.
Currently:
Hero hits gold coin and gains +1 and when he dies it minus how many coins the hero obtained. (which i have working now)
Want to add:
Hero hits red coin and its a random(5,25) but when he dies i want that random number to also be removed.
Issue:
Just not sure how to write the script so when hero dies it removes gold and red coins. Like i said above the gold coin setup was easy its the random im having issues with.
Thanks Again
WhyCali
For the red coins, store the random number you generate in an attribute. Then when the player dies use that attribute to subtract from the red coins.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
@jamie_c
Ok so for the showing the coin number its under game.coins and currently setup
When Hero touches our collides with goldCoin
Change Attribute
game.coins to game.coins+1
Change Attribute
game.coinCollected to game.coinCollected+1
When dies
Change Attribute
game.coins to game.coins - game.coinCollected
how do i add the randoms to also work for game.coins. i understand adding an attribute but not sure how to write to code so it knows what the random number was and to make sure it pulls it correctly and displays it in game.coins
When you generate the random number for the red coins, do something like this:
Change Attribute redCoin to random(5, 25)
Then you can add redCoin to Coins with:
Change Attribute Coins to Coins + redCoin
Also when the player dies you can subtract it like this:
Change Attribute Coins to Coins - redCoin
So really all you are doing is storing the random number you generated once to use again as needed. Hope that helps.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
@jamie_c
Now that makes perfect sense. Thank you so much. oh by the way i have watched alot of your video's and they are F%$king (sorry for the language) amazing. Thank you again for what you do for GS.
You're welcome, and glad you've like the videos.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page