# How do I make something happen each 100 on a variable?

Get help using Construct 2

### » Wed Jun 10, 2015 2:50 am

(I'm keeping this simple, and only giving you the info you need to know to answer) So I want my player to level up each time they reach 100 exp, and I cant make it for like once 200, 300, and forever, so I need a way to make it EVERY TIME THE VARIABLE HAS CHANGED BY 100.
Thanks!
Alright, I've been thinking. When life gives you lemons, don't make lemonade! Take the lemons back! GET MAD! I DON'T WANT YOUR DANG LEMONS WHAT AM I SUPPOSED TO DO WITH THESE?! Demand to see life's manager!! Do you know who I am!?!?! I'M THE MAN WHOS GONNA BURN YOUR HOUSE DOWN... WITH THE LEMONS
B
17
S
9
Posts: 157
Reputation: 2,150

### » Wed Jun 10, 2015 3:28 am

You're going to want to check if your experience value can be divided by 100 with a remainder of 0.

For this, there is the modulo operator %. Modulo gives you the remainder of a division.

examples:
200 % 100 = 0
301 % 100 = 1
950 % 100 = 50

therefore:
if experience % 100 = 0 then you know the experience is a multiple of 100.

This won't work if they surpass the multiple of 100, going from 99 to 101 for example, so you'll have to do something a bit fancier like this:

(Warning, some math and programming shenanigans)

It boils down to this condition, which I will attempt to explain:

floor( currentExp / expNeededToLevel ) > floor( oldExp / expNeededToLevel ) -> if true, level up!

"floor()" rounds whatever is in parenthesis down to the nearest integer (whole number). So 0.9 would round to 0 -- and 1.1 would round to 1.

"expNeededToLevel" is the amount of experience needed in order to level up (in your case this is 100).

"oldExp" is the experience value BEFORE adding new experience.

"currentExp" is the experience value AFTER adding new experience.

">" is the "greater than" operator and checks if the value on the left of it is greater than the value on the right of it, and says true (1) or false (0) about it.

So if your character had 99 experience, then killed a bug and gained 2 experience, it would go like this:

expNeededToLevel = 100
oldExp = 99
currentExp = 101 (after adding 2 for the bug)

So if you remember the condition from above:
floor( currentExp / expNeededToLevel ) > floor( oldExp / expNeededToLevel )

If I plug in the values you get:
floor(101 / 100) > floor(99 / 100)
which reduces to:
floor(1.01) > floor(0.99)
after floor reduces to:
1 > 0
meaning "one is greater than zero" which is a true statement, so your character needs to level up!

You can replace 100 with any number of experience you want.

I hope this helps you.
B
12
S
4
Posts: 48
Reputation: 910

### » Wed Jun 10, 2015 12:25 pm

@Valhallen
"floor( currentExp / expNeededToLevel ) > floor( oldExp / expNeededToLevel ) -> if true, level up!"
When I compare you can't enter floor into the variable...
can I get more explaination on floor? I know what it does, but how do I add it in?
I get a dropdown box, so I cant enter in floor()
Alright, I've been thinking. When life gives you lemons, don't make lemonade! Take the lemons back! GET MAD! I DON'T WANT YOUR DANG LEMONS WHAT AM I SUPPOSED TO DO WITH THESE?! Demand to see life's manager!! Do you know who I am!?!?! I'M THE MAN WHOS GONNA BURN YOUR HOUSE DOWN... WITH THE LEMONS
B
17
S
9
Posts: 157
Reputation: 2,150

### » Wed Jun 10, 2015 1:39 pm

I've haven't actually used Construct 2 yet, but I see in the documentation there is a System Condition called "Compare two values" which can take two expressions.

An expression is something that needs to be evaluated before the condition is checked. You can type it right in, instead of a simple number.

Compare two values
Compare any two expressions (which can either numbers or text) with each other. They can be compared as Equal, Not equal, Less, Less or equal, Greater or Greater or equal.

You'll want to use the "Greater" comparison.

I plan on testing out Construct 2 tonight, so I'll come back and add some more detail to this post if you haven't figured it out by then.
B
12
S
4
Posts: 48
Reputation: 910

### » Wed Jun 10, 2015 3:49 pm

Hm, for now (until I get a response from you) I'll use change by 1, and lower the value to level up for each 30.
Alright, I've been thinking. When life gives you lemons, don't make lemonade! Take the lemons back! GET MAD! I DON'T WANT YOUR DANG LEMONS WHAT AM I SUPPOSED TO DO WITH THESE?! Demand to see life's manager!! Do you know who I am!?!?! I'M THE MAN WHOS GONNA BURN YOUR HOUSE DOWN... WITH THE LEMONS
B
17
S
9
Posts: 157
Reputation: 2,150

### » Wed Jun 10, 2015 4:11 pm

@Valhallen Hi, I figured I could do the simple way, because my exp always changes by 5.
But when the players XP is EXACTLY on 100, it will rapidly change the level by 1 because the statement of the player having a multiple of 100 is STILL true, so my player could hack.
Alright, I've been thinking. When life gives you lemons, don't make lemonade! Take the lemons back! GET MAD! I DON'T WANT YOUR DANG LEMONS WHAT AM I SUPPOSED TO DO WITH THESE?! Demand to see life's manager!! Do you know who I am!?!?! I'M THE MAN WHOS GONNA BURN YOUR HOUSE DOWN... WITH THE LEMONS
B
17
S
9
Posts: 157
Reputation: 2,150

### » Wed Jun 10, 2015 4:54 pm

You should make sure that you only check the condition one time when experience is added, rather than on tick or at an interval.

Alternatively you could keep track of how much experience has been gained since the last level up. If that value becomes greater than 100, then level up and set it back to 0.
B
12
S
4
Posts: 48
Reputation: 910

### » Wed Jun 10, 2015 10:47 pm

Its working now
Thanks =)
Alright, I've been thinking. When life gives you lemons, don't make lemonade! Take the lemons back! GET MAD! I DON'T WANT YOUR DANG LEMONS WHAT AM I SUPPOSED TO DO WITH THESE?! Demand to see life's manager!! Do you know who I am!?!?! I'M THE MAN WHOS GONNA BURN YOUR HOUSE DOWN... WITH THE LEMONS
B
17
S
9
Posts: 157
Reputation: 2,150