about random numbers

whycaliwhycali 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

  • whycaliwhycali Member, PRO Posts: 87

    Sorry after rereading this I meant to say when hero dies I take away the coins they might have gained.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    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'.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    It's not clear. What do you mean by "remove them"?

  • whycaliwhycali Member, PRO Posts: 87
    edited May 2018

    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

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    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.

  • whycaliwhycali Member, PRO Posts: 87
    edited May 2018

    @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

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    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.

  • whycaliwhycali Member, PRO Posts: 87

    @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.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    You're welcome, and glad you've like the videos. :)

Sign In or Register to comment.