"mod" system function to calculate remainder

0 favourites
  • 6 posts
From the Asset Store
Create complex dialogues with ease with this tool/template!
  • Hi,

    I don't see a "mod" (for modulu) system function, to find the remainder for division. Is very useful for creating additions that stay in a range. For exampe, suppose i want to create a little game that pressing a button steps through all frames of an animation. If i know that there are say animations 0 to 5, then you can use a mod function as follows:

    current frame = (current frame + 1) mod 6

    set animation frame to (current frame)

    this will conveniently guarantee that you circle through the frames.

    But, i guess there is no mod system function. Could one be offered?

    Dan

  • EDIT@ Don't think I've got it right. >.>

  • thanks.

    But the behavior i need is as follows:

    Button pressed --> show next frame unless already at max frame, then show frame 0

    I imagine loop would just loop through all frames without "waiting" for the button to be pressed. Or, is there another way to use loops?

  • https://www.scirra.com/manual/78/expressions

    It's the % operator.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ahh, great! thanks. I missed the operators.

  • thanks.

    But the behavior i need is as follows:

    Button pressed --> show next frame unless already at max frame, then show frame 0

    I imagine loop would just loop through all frames without "waiting" for the button to be pressed. Or, is there another way to use loops?

    Ok, what you need is a local variable "frame" (you can call it anything). On press the button, set "frame" to "frame"+1 and set object animationframe to "frame". And make a condition If "frame" > objects frame count then set "frame" and animation frame both to 0.

    EDIT@ Oh there is the operator already. Cool.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)