Help with math problem?

Basically what I’m trying to do is to have levels unlocked based on a saved integer variable. I got the whole saving/loading set up but I’m having trouble on how to tell my BP to unlock based on the variable.

Trying to get:
If Var is 0, unlock level 1;
If Var is 1, unlock level 2;
And so on.

Currently doing in BP:
If Var = 0, set VarUnlocked to 1
If Var = 1, set VarUnlocked to 2
Etc.

  • VarUnlocked is only a variable within the widget bp to change the button and set it to accept input

The problem I’m having with the above method is only level 2 unlocks when Var=1, level 1 locks again as Var is not 0.

So I tried setting Var = 0 OR <8, Var = 1 OR <8, etc. and it works of course…until I tried my reset button to reset Var to 0, all levels are still unlocked because they all have <8 in BP. Using AND nodes doesn’t work too as Var=1 AND <8 still locks level 1. I’m no math wiz so help me out guys…am I using the <> symbol the wrong way?

Where you are unlocking levels? I think your condition to unlock your level is not being checked after you set variable to 0 and your level remains unlocked. If you can provide screenshots of where you are checking conditions to unlock level and setting var to 0, then it will be easy to understand.

Will try when I’m at my computer again, but basically the flow on how I implement unlock is:

There’s a level select menu, with individual buttons for each level. Each button will only open the associated level when Var is of certain value. Otherwise any clicked event will not do anything, so it’s ‘locked’. It’s kind of messy on bp but it works, the only problem is the variable formula?

Just occurred in my mind, is there any node that allows me to specify a range so I can just say

If var is 0-3, then unlock levels 1,2 & 3? A range formula perhaps?

Since the unlocked level in your case is always Var+1, all the information you require is given to you by the value of Var. VarUnlocked is redundant. A simple Pure function like this is all you need:

59035-levelunlocktest.png

From there, if you want to respond internally or update other objects in response to Var changing, make Var private and create a setter function for it:

This requires you to know how many levels you have, but it sounds like you have that information. The for loop is the key part that makes this logic work, so while your implementation may not look like this example, you’ll likely need to use it somewhere in your implementation.

You will need to use a for loop here.

For example, if your var is having value 3, then it means first four levels should be unlocked. SO you should keep an array of UnlockedLevel values.

Then you can use this array and check what value it contains , if it have that value then you can unlock level, otherwise not.

59065-contains.png

Ok I haven’t had the time to try out the above suggestions but seems like it would require me to revamp my entire set up, which I’m actually reluctant to do so especially when I have a limited time. But for those curious to know, I ended up creating a boolean array in my Saved Game blueprint and changed my game to just switch selected indexes to True. so whenever a user completed a level, it changes the value at specific indexes. This seems like a better way for me too as I can now have more flexibility and depth on the gameplay ie. level will lock again when user failed a critical level to story etc. You can do that with other variables too but it’s easier for me to understand and keep track of what I’m doing. Thanks for the suggestions though!