[SOLVED] Is there an action to end a function so it doesn't keep checking other conditions?

I have a condition set up so when a button is pressed it increases a number by an amount depending on that same number’s current value.

For example, if the number is less than 10 the button increases it by 1 each time.
However, if the number is not less than 10 (it’s 10 or higher) it increases by 2 each time.

The problem I run into is…

When the value gets to 9 and the button is pressed, it checks the first condition (which is true) and increases the value to 10. Then it checks the second condition, which has since been also made true. It’s no longer less than 10 (it’s equal to 10) so it adds another 2 points, bringing it to 12.

So, when the value is at 9 and the button is pressed it suddenly jumps to 12.

Is there a way to end the function if one of the conditions is met? Or, am I going about this all wrong?

It’s easier if you post a pic of the events. In your case, I believe it will work if you reverse the order of events.

If button is released
– variable ≥ 10 variable + 2
– variable < 10 variable + 1

Or you could always add 1 and if ≥ 10 add another 1

If button is released – variable + 1
– variable ≥ 10 variable + 1
.

Hey Keith! Thanks for responding. I’d previously tried changing the orders around but I actually have more than 2 conditions I’m working with (>10, >20, >30, and so on). Using that method, I couldn’t figure out how to make it so that only 1 of the conditions is ever acted on, even if several happen to be met.

Your second suggestion would actually work great! It gets a little confusing to keep track of how much should be added each time (with multiple conditions being met each time) but I could definitely do it like that and hadn’t thought of that. So thanks very much for the suggestion!

Actually, when I’d gotten frustrated last night and laid down at like 5am it hit me that I could use a boolean variable that basically “asks” each condition whether or not a prior condition had already been met (therefore, whether or not subsequent conditions should act). I’ll post a screenshot of the solution I’d worked in case it helps anyone else having my problem.

For those who are having a similar issue it basically works like this:

On click, every time, the boolean is set to TRUE. The function goes down the list checking each condition’s requirements in order. Every single condition, however, also requires (“AND”) the boolean to be TRUE to go off. The first condition that meets the numerical requirement AND the boolean requirement acts. At the end of every condition there’s an action that sets the boolean to FALSE, thereby disabling all subsequent conditions from being able to act, even if they meet the numerical requirement. Another button press will then reset the boolean to TRUE, allowing conditions to act until one sets the boolean back to FALSE.

Thanks again, Keith, for the suggestions. Good to look at issues from different angles sometimes.

Also, hope this thread helps someone else!

1 Like

I’m glad you figured it out. FYI: the & isn’t needed. All conditions are treated as if all the conditions are true by default. & are really only useful inside an or condition.

Here’s a slightly streamlined version. I like to use changed but you use what works for you.

If there’s a pattern to your points increase then you could probably create a formula to calculate it based off the level something like points = level * 1.015 or something.

Thanks for offering your more streamlined version! I haven’t taken a close look at it yet but once I wrap my head around it I’ll put it to good use.

As to your suggestion of using a coefficient to set an increase pattern, I’ll offer up my specific usage (just for curiosity sake):

• My levels will go from 1 to 1000 max.
• Level 1 has a value of 0. Level 1000 has a value of 10,000,000.
• Every click of a button will increase the level by 1 and its value by a static coefficient (1.001205 or some such) so that by the time you reach level 1000 the value is roughly 10,000,000.
• Early levels, however, end up being such small increases that instead of multiplying by the coefficient I’d rather simply add 1 to them until they reach such a level that using the coefficient would garner an increase of AT LEAST 1.

(ie. I don’t want the player to reach level 5 and their value still reads as 1! Haha!)
So levels 2, 3, 4, 5, and so on would just increase 1 per click. But somewhere around level 600, or whatever, would end up increasing by several thousand per click.

If you couldn’t tell, which I doubt, I’m really new to the Gdevelop program and new to programming in general so I really appreciate the helpful suggestions. I’ll take out the &'s to keep things cleaner and probably work off of your cleaned up version.

Thanks buddy!

1 Like