How do I shorten this sequential code?

  • 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?

  • 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 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.

  • 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...?

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Many thanks. I was thinking to use modulo but never done it before in Construct 2. Thanks!

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