If Score/10 = whole number...

0 favourites
  • 11 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • In my game whenever the player gets a score of 10, 20, 30 ... 1210, 1220 etc (basically any score that is wholly divisible by 10) I want an event to run.

    There's a way in programming that runs something like this:

    If a number is divided by 10 and the result is a whole number (1, 2, 3 etc) then run this function...

    I can't remember the name of this type of function, but is there a similar way of doing this in Construct, where If Score/10 = Whole Number then execute Function

    Thanks all :)

  • I don't know this function that you are looking for but you can do as workaround:

    You can compare the result of score/10 with: round(score/10)

    If is not equal is because the result of score/10 is not a whole number.

    Edit:

    I found it.

    Just compare: score%10 and compare it with 0

    If score%10 = 0

    - Whole Number

    Else

    - Not Whole

  • Brilliant. Float - that was the term I couldn't remember.

    Thank you :)

  • OK - so float(Score)%10 is the expression I need, but how do I complete the following:

    System > float(Score)%10 -> If the result is a whole number then do A, else do B

  • System->Compare two values

    Score%10

    = Equal to

    0

    You'll probably want a Trigger once also.

    Via Copy as text:

    + System: Score%10 = 0

    + System: Trigger once

    -> (no actions)

    You don't need float().

  • OK - so float(Score)%10 is the expression I need, but how do I complete the following:

    System > float(Score)%10 -> If the result is a whole number then do A, else do B

    Don't create a system expression... if you do this it will trigger every tick what means that it will test Score%10 every moment even without change the value of the score.

    What I suggest..

    In the same action that increment the Score value, create a sub event (That means that this sub event will only trigger when the Score changes)

    So it will be like:

    Trigger that increment Score

    + (Sub Event) If Score%10 = 0 -> ACTION

    + ELSE -> ANOTHER ACTION

    You only need float() if you are working with a string like I was in my example.

    If you are working with numbers, just do straight Score%10

  • The function I need isn't If Score%10 = 0

    The function I need is If Score % 10 = a whole number > then DO THIS...

    --> ELSE do this...

    eg:

    * 6%10 = 6 (whole number) > DO THIS...

    * 5%10 = 0.5 (not whole number) > ELSE...

    So whats the expression for Whole Number?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Bootfit , blackhornet already answered you.

    The following "Score%10 = 0" is checking if it's a whole number, therefore telling you if the score is divisible by 10 or not. The "Zero" means that this division have 0 remains, so it's a whole number.

    Then...

    If Score%10 = 0 (If whole number)

    sub-action{Do something}

    Else

    sub-action{Do something}

    in Order to not call it every thick, you can do it by what blackhornet said or put it inside a Function which will be called every time the Score changes. Like this:

    On Function "Check Score" Called

    If Score%10 = 0 (If whole number)

    sub-action{Do something}

    Else

    sub-action{Do something}

  • When you use % and compare to 0, if = 0 it means that the number is divisible by 10 as you asked before.

    For example:

    10%10 if = 0 means that the first number is divisible by the second.

    Is score divisible(%) per 10? If yes you need to compare with 0 to know.

    Is the same as is the result of score/10 = a whole number?

  • When you use % and compare to 0, if = 0 it means that the number is divisible by 10 as you asked before.

    For example:

    10%10 if = 0 means that the first number is divisible by the second.

    Is score divisible(%) per 10? If yes you need to compare with 0 to know.

    Is the same as is the result of score/10 = a whole number?

    https://en.wikipedia.org/wiki/Modulo_operation

    Quick capx I wrote finding odd and even numbers with modulo.

    https://www.scirra.com/tutorials/9439/modulo-odd-even

  • OK, so to definitely show how it works I did a simple project showing the result.

    So, what it does?

    Every 0.5 seconds, it will increase 1 to the Text box called Score.

    - It will calc Score /10 and Score %10

    After that, it will compare IF Score%10 is equal to 0, if IS so, say WHOLE NUMBER else, NOT A WHOLE NUMBER.

    And you can see that it works as you asked, because it only show WHOLE NUMBER when also Score/10 = whole number and Score%10 = 0.

    And it works for any number if you change %10 to %8 it will be a WHOLE NUMBER only when the Score is divisible by 8.

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