Set an attribute in multiples of a value

GamepencilerGamepenciler Artist/Game DeveloperMember, PRO Posts: 326
Hello sorry to bug the awesome people in here. I just have logical question
If I want a value that triggers in muliplication like 5 (5,10,15,20) without any triggering other numbers, what function will I use or is it just logical? how?

An example to where will I use this is when a player collects every 5 coins he will automatically unleash a power up.

-thanks people

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    i would do something like this

    set score to (score+1)%5
    score will continue to incvrement to infinity, but the %5 will group it in groups of 5, and score display values of 0,1,2,3,4,0,1,2,3,4,0,1,2,3,4

    play around with it and it should do what you want.
  • GamepencilerGamepenciler Artist/Game Developer Member, PRO Posts: 326
    that's a new trick for me,.. thanks @jonmulcahy :)
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    You can use modulate to knock an attribute back to zero. Then call the powerup each time the number hits zero. So with a modulate of 5 the coin count goes 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0 ...

    The issue with this is the player would get a powerup as the game starts. So some logic is needed to prevent that.

    So the code for the modulate would be.

    Constrain game.powerUp to game.coins%5

    Then a rule that says. 'All' conditions match

    if game.coins (is greater than or equal) to 1.
    and if game.powerUp = 0

    Then perform powerUp.

    That way the player has to have collected a coin for it to perform.

    And the powerUp will hit 0 on the fifth coin every single time.

    This should work for you - I just did this in my head so if you have problems let me know :)

    Cheers, M@
  • GamepencilerGamepenciler Artist/Game Developer Member, PRO Posts: 326
    Ok thanks @matarua quite a help :)
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @jonmulcahy snap!
  • GamepencilerGamepenciler Artist/Game Developer Member, PRO Posts: 326
    yeah specially @jonmulcahy :)
  • GamepencilerGamepenciler Artist/Game Developer Member, PRO Posts: 326
    Ouch i just tried (game.score+1)%5 not only that it doesn't work but when I checked back the value is gone leaving the text field at 0 :( any other ideas >.< ?
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @ecanhoj I have tested what I said from my own projects and it works fine. Email your project perhaps or type out all the code here in full correctly and very clearly and may be we can help you get to the bottom of it :)
Sign In or Register to comment.