[Solved] Level selection and animation

I am developing a level selection screen for my game. It consist of multiple similar buttons and unlocks levels (change states) at the completion of each level using the Global variable “CurrentLevel”.

I am facing two problems:

  1. Lock/unlock button animation per “CurrentLevel” variable. My requirement is buttons corresponding to any levels higher than the CurrentLevel value must be in the Locked state and any buttons corresponding to the levels lower than the CurrentLevel value must be in the unlocked state. While I am able to achieve this with small number of levels, the logic is not scalable with large number of levels. I am looking for an event/action something like this:

Event:
The global variable CurrentLevel = X

Action
Set Animation of LevelIcon1 to LevelIconX to Unlocked

I am sure there must be an efficient way to achieve this using events and actions. However, I am not able to figure that out.

  1. I have multiple buttons and text for different levels (One button and one text for each level). An ideal solution that I am looking for is to have dynamically generate text on different instance of button per global variable “CurrentLevel”. Any buttons corresponding to the levels higher than the current level remains in the locked state. Currently, I am achieving this by having text object for each level and showing it only when the level is unlocked (represented by CurrentLevel var). This means that that one button and one text object for each level. Again, this is not scalable.

This is how I am trying to achieve the above two goals:

LevelButtons is a group of all level buttons like LevelIcon1, LevelIcon2. I don’t know if there’s a way to cycle through all objects in the group and set their animation status based on CurrentLevel value.

Appreciate your insights and suggestions!

You’ve gone about this the wrong way. You’ve created a button for each level using the same images.


What you should do instead is make one button object named LevelIcon with the two images and an instance variable names "Level".

Place an instance of the LevelIcon at each position where the existing buttons are located, and set the Level variable to the level the LevelIcon represents.

Then create 3 events:

Condition: Variable Level of LevelIcon < Variable(CurrentLevel)
Action: set animation of LevelIcon = “Normal”

Condition: Variable Level of LevelIcon > Variable(CurrentLevel)
Action: set animation of LevelIcon = “Locked”

Condition: Variable Level of LevelIcon = Variable(CurrentLevel)
Action: set animation of LevelIcon = “Unlocked”

1 Like

Worked like a charm! Thank you for helping me understand how to use instance variable. I was looking for any event/condition with something like “instance variable” instead of setting it up in the Properties.