"mod" system function to calculate remainder

Discussion and feedback on Construct 2

Post » Wed Apr 02, 2014 7:48 pm

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
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Apr 02, 2014 7:50 pm

[email protected] Don't think I've got it right. >.>
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099

Post » Wed Apr 02, 2014 7:53 pm

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?
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Apr 02, 2014 7:54 pm

Scirra Founder
B
395
S
233
G
88
Posts: 24,376
Reputation: 193,842

Post » Wed Apr 02, 2014 7:55 pm

Ahh, great! thanks. I missed the operators.
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Wed Apr 02, 2014 7:57 pm

grossd wrote: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.

[email protected] Oh there is the operator already. Cool.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
89
S
30
G
22
Posts: 1,985
Reputation: 20,099


Return to Construct 2 General

Who is online

Users browsing this forum: tarek2 and 7 guests