How do I use a string variable as the name of the variable I'm trying to get?

0 favourites
  • 4 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • I will try to make this as simple as possible because something tells me it's super easy.

    I have a sprite called Character. It has 10 different variables we'll call A, B, C, D, E, etc etc. that hold a number between 1 and 9.

    Now I have a Family of sprites that called Billfam. I made a family instance variable called Letter. On the start of layout on the Event Sheet, I have assigned all of the 10 members of the family Letter = A through J.

    My question is, If I want to make an event that pulls the number held by that specific Family members Letter. How would I do it?

    I tried Character.(Billfam.Letter) but that doesn't work. help please

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you have one object type Character you don't need to use a Family. In general though if i'm understanding what you want correctly, you can access through some condition : if Family.letter=A, set var to family.A

  • Thank you for your reply. The family is for a different group. What I'm looking for is the ability to pull up an instance variable's value using a string from another instance variable.

    for instance character.a = 1 and character.b = 2

    I want to make a family code like

    if billfam is visible. ( set family variable ( billfam.number ) as (Character.(billfam.letter) The key. to all of this is finding a way of utilizing a variable to pull the information from another variable.

    well whatever I can do to make that. I can do it the hard way but I feel like this has to be something that can be done.

  • I think you can't access the variable in the way that you're describing. Based on the design of the game and how letter are used maybe there is a better way to do it in general though. For now you can just use condition, if family.type=A then set var to family.A. You could use a function where you send through the type as a parameter then apply as necessary.

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