Modulus Function Help

I want a scenario where when a block goes off screen, it adds to a counter, call it "blockcount" (which I already have got going). Once "blockcount" is divisible by 10 completely, I want the value of block count to pass into another attribute. I think I need to use the modulus function but I don't really know how. Any ideas?

Comments

  • DenimSharkDenimShark Member Posts: 192
    Have a new variable and constain it to blockcount%10. Then have a rule when newvariable = 0, do your passing of blockcount to wherever
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Try this instead.
    game.ConstantZero = 0
    Rule: if game.ConstantZero = mod(game.blockCount,10)

    1 less constrain, and try to shift over to using the mod(x,y) function instead of %.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    That will work fine but you also have to make sure it doesn't trigger when blockcount equals zero.

    If you want to avoid a constrain behavior, create an integer attribute named game.ZERO and give it a value of zero. Then, create a rule that says When [all conditions] attribute game.blockcount>0 AND game.ZERO=game.blockcount%10 ... [rules]

    I assume you're wanting to keep a tens counter or something along those lines?

    So it would be:

    When attribute game.blockcount>0 AND game.ZERO=game.blockcount%10
    .....Change Attribute game.tensCount to game.tensCount+1
    .....Change Attribute game.blockcount to 0

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • DenimSharkDenimShark Member Posts: 192
    Good point. Would be even easier if you guys allowed the editor to work on the left side of equations. Any way that'll happen?
  • KenAdamsKenAdams Member Posts: 4
    Thanks everyone for the quick response! Got it working all well.
Sign In or Register to comment.