# How do I shorten this sequential code?

Get help using Construct 2

### » Tue Aug 25, 2015 2:43 pm

From lines 4 to 6 in tab MainES as per attached .capx how would I shorten this so that it is a loop or algorithm of some sort? I want it to sequentially add each multiple of 25 to variable milestone, so 25,50,75,100,125,150,175,200,225...... how would I do this rather than writing it out for every single number?

http://filebin.ca/2DMmDIpPTp0i/Clickhah.capx
B
10
S
3
Posts: 109
Reputation: 1,080

### » Tue Aug 25, 2015 3:01 pm

Well... I don't have access to a comouter right now so I could not understand fully the event sheet (only read the xml file) however it seems that when score is superior or equal to 25, you set the milestone to 50, then when equal or more than 50, you set to 75, etc..

I would have made it so:

Set milestone to (floor(Score/25)+1)*25

(Floor(25/25)+1)*25=(floor(1)+1)*25=50
(Floor(50/25)+1)*25=(floor(2)+1)*25=75
(Floor(26/25)+1)*25=(1+1)*25=50

Floor is a system expression that returns the number rounded down, and can be typed directly in the event sheet.

Floor(score/25) will return 0 for score between 0 to 24.99999.... 1 for score between 25 to 49.9999...

Adding 1 to that number then multipying by 25 should makes the milestone being the next 25 multiple you can reach.

If it is possible to actually score more than 25 in one tick(frame) then you should take that into account if the milestone gives you a bonus.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

### » Tue Aug 25, 2015 3:04 pm

I can't figure out how to put what you have told me into the event sheet, do I put all of it in what you have mentioned, just one part of it etc...?
B
10
S
3
Posts: 109
Reputation: 1,080

### » Tue Aug 25, 2015 3:21 pm

B
71
S
22
G
268
Posts: 3,809
Reputation: 148,249

### » Tue Aug 25, 2015 3:32 pm

Ok I so I tried the first part of Local number thinking this is an instance variable, I have no idea how you have done this, can you upload the .capx please?
B
10
S
3
Posts: 109
Reputation: 1,080

### » Tue Aug 25, 2015 3:45 pm

@SomeT

I did almost the same thing as blackhornet, but without the local variable, and used MOD (%) to see if score is at a multiple of 25... (MOD calculates the remainder of dividing score by 25. If there is no remainder then you know you have a multiple of 25.)

I also moved updating Milestone to where the Score is increased (like blackhornet did), so that you don't have to worry about Trigger Once, and don't have code running every tick that doesn't need to run.

http://www.rieperts.com/games/forum/Clickhah.capx
Last edited by AllanR on Tue Aug 25, 2015 3:51 pm, edited 1 time in total.
B
99
S
35
G
20
Posts: 438
Reputation: 17,930

### » Tue Aug 25, 2015 3:51 pm

Many thanks. I was thinking to use modulo but never done it before in Construct 2. Thanks!
B
10
S
3
Posts: 109
Reputation: 1,080