Mod() help please, not getting it :(

I have an attribute called "correctRun", this basically keeps getting incremented by 1 if the user gives the correct answer

eg:
game.correctRun=game.correctRun+1

I then have this rule underneath:
game.correctRun=mod(game.correctRun),20)

  • display level up graphic

so I want the second rule to "fire" everytime correctRun is 20,40,60,80 etc

but for some reason the second rule fires everytime (eg: 1,2,3,4,5,6 etc) any idea what I am doing wrong?
This is the first time I am using this function in GS so I'm kind of confused.

Thanks!
(Attaching the image below as maybe I setup the rule wrong? )

Comments

  • colandercolander Member Posts: 1,610
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2015

    The mod() function returns the remainder of a division problem. So mod(1,20) would equal 1 since 1 divided by 20 would be 0 with a remainder of 1.

    If you evaluate both sides of game.correctRun=mod(game.correctRun,20) with a few sample values, you'll see that both sides are equal up to 19 and then unequal after that:

    1=1%20=1 true
    2=2%20=2 true
    3=3%20=3 true
    ...
    19=19%20=19 true
    20=20%20=0 false
    21=21%20=1 false

    To trigger a rule at every multiple of 20, you want mod(game.correctRun,20) to equal 0, meaning that there is no remainder when dividing game.correctRun by 20.

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

  • ryastryast Member Posts: 145

    Perfect! Thank you for the help!

    I have used it in Java and PHP, but for some reason completely got it wrong in GS... could be because of lack of sleep ;) :p

    Cheers!

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

    You're welcome... any other questions, just ask!

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

  • SocksSocks London, UK.Member Posts: 12,822

    @tatiang said:
    You're welcome... any other questions, just ask!

    If an attribute called 'actor' belonging to an actor called 'actor' is changed to the value -100, and then this actor is constrained to linear velocity x = 'actor' then why actor of actor no go right ?

  • colandercolander Member Posts: 1,610

    @Socks said:
    If an attribute called 'actor' belonging to an actor called 'actor' is changed to the value -100, and then this actor is constrained to linear velocity x = 'actor' then why actor of actor no go right ?

    What attribute type did you use? If you used "real" that will be the problem. Real is really not real it's fake. It's a joke played on us but the GS staff try using an integer and it should all work fine.

  • SocksSocks London, UK.Member Posts: 12,822

    @colander said:
    What attribute type did you use? If you used "real" that will be the problem. Real is really not real it's fake. It's a joke played on us but the GS staff try using an integer and it should all work fine.

    I used a real integer attribute value table, I used this to store the fake attributes so they didn't get injured.

  • colandercolander Member Posts: 1,610

    @Socks said:
    I used a real integer attribute value table, I used this to store the fake attributes so they didn't get injured.

    Ahh! nice work around, get that into you GS the joke is back on you.

Sign In or Register to comment.