Dynamic instance variable reference?

0 favourites
  • 3 posts
From the Asset Store
Create your quiz game! Create unlimited categories. Manage categories and questions
  • Is it possible to construct a dynamic instance variable reference.

    Let's say an NPC has instance variables with the following names:




    It also has an instance variable called DialogueState, which stores the name of the current dialogue to be written (for example Dialogue1).

    Is it possible to refer to the Dialogue1 instance variable based on the DialogueState instance variable? In other words, can I construct the instance variable reference dynamically using DialogueState to determine which instance variable I want to take the value from?


  • Dictionaries are useful for this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If there are only 3 instance variables, you can use a ternary operator. For example:

    Set text to (DialogueState=1 ? NPC.Dialogue1 : DialogueState=2 ? NPC.Dialogue2 : NPC.Dialogue3)

    Otherwise use a dictionary as oosyrag suggested - add the dictionary to the same container with NPC, each NPC will have its own copy of it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)