How do I do something every Nth time?

Get help using Construct 2

Post » Mon Jul 21, 2014 9:50 am

Hi!

I have two global numbers (a, b) and i want to add "b" 1 when "a" equals to 10, 20, 30, 40, 50, 60, ...etc. How to do that?
B
3
Posts: 4
Reputation: 179

Post » Mon Jul 21, 2014 10:01 am

You could simply use the System-Compare two values condition.

First value would be Global variable "a", and compare values would be "10|20|30|40..." etc then set Action to add 1 to Global 'b'.

For more info on Expressions, see https://www.scirra.com/manual/78/expressions.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
86
Posts: 5,418
Reputation: 59,522

Post » Mon Jul 21, 2014 10:27 am

zenox98 wrote:You could simply use the System-Compare two values condition.

First value would be Global variable "a", and compare values would be "10|20|30|40..." etc then set Action to add 1 to Global 'b'.


Yes, it would be simple, but I still want to add 1 to "b" when "a" is 18965484848321850. It's impossible to do it by the way you said because number "a" has no limits. So i hope there's an easier way to do it.
B
3
Posts: 4
Reputation: 179

Post » Mon Jul 21, 2014 10:37 am

What does "a" represent?
If you are saying that "a" could be any unknown numerical value, then without some kind of algorithm or boundary, it will be impossible to test.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
86
Posts: 5,418
Reputation: 59,522

Post » Mon Jul 21, 2014 10:45 am

First you have to understand when you want to check the b's value; my guess is that you will check it when b changes value, so in that event you can put the comparing.
I'm not a insane, my mother had me tested

I'm an engineer. To save time, just assume I'm never wrong
B
30
S
13
G
4
Posts: 141
Reputation: 4,832

Post » Mon Jul 21, 2014 11:16 am

Hi see if this helps
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Mon Jul 21, 2014 1:19 pm

To make things clear: I have a sprite. When It's clicked its gonna add 1 to "a". I want to make when "a" reaches 10, 20, 30, 40, 50, 60, 70 and so on to add 1 to "b". Like this:
a=10 b=1
a=340 b=34
a=555 b=55
a=29 b=2
B
3
Posts: 4
Reputation: 179

Post » Mon Jul 21, 2014 1:36 pm

IceTeaDestroyer wrote:To make things clear: I have a sprite. When It's clicked its gonna add 1 to "a". I want to make when "a" reaches 10, 20, 30, 40, 50, 60, 70 and so on to add 1 to "b". Like this:
a=10 b=1
a=340 b=34
a=555 b=55
a=29 b=2

Try "On sprite clicked" > "Add 1 to value "a"" & "Set value "b" to (floor(a/10))".

see my example:
example.capx
You do not have the required permissions to view the files attached to this post.
B
22
S
9
G
7
Posts: 421
Reputation: 6,543

Post » Mon Jul 21, 2014 1:58 pm

Sisyphus wrote:
IceTeaDestroyer wrote:To make things clear: I have a sprite. When It's clicked its gonna add 1 to "a". I want to make when "a" reaches 10, 20, 30, 40, 50, 60, 70 and so on to add 1 to "b". Like this:
a=10 b=1
a=340 b=34
a=555 b=55
a=29 b=2

Try "On sprite clicked" > "Add 1 to value "a"" & "Set value "b" to (floor(a/10))".

see my example:
example.capx


Thanks It works now!!!
B
3
Posts: 4
Reputation: 179

Post » Mon Jul 21, 2014 2:15 pm

IceTeaDestroyer wrote:Thanks It works now!!!

You're welcome! I saw screenshot of your event sheet, better use sprite font instead of text object, using text objects can kill performance.
B
22
S
9
G
7
Posts: 421
Reputation: 6,543


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 46 guests