How do I reference an object using a string?

0 favourites
  • 2 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I am building a level navigation menu, so here's how it works.

    When the player completes a level, I add 1 to a variable called LevelsCompleted.

    If a level access button's level number is equal to the number of levels completed + 1 (because there is already level 1), I set it visible (if it's not, I set it invisible). But the problem is, I have to reference the level button using a string ("Level" & LevelButton.LevelNumber), how do I do that.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't understand your setup. Are level buttons instances of one sprite? Or are they different sprites?

    The easiest way is to make one sprite object LevelButton, and add "Level" instance variable to it. Manually set level numbers to all buttons in the layout editor. Then you can use "LevelButton compare variable" to reference them.

    For example:

    LevelButton compare variable Level>(CurrentLevel+1)
    	LevelButton set invisible
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)