How do I pick an object by name (string)?

0 favourites
  • 9 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi! Is it possible to use a string in a variable to pick an object?

    I have 2 Dictionary objects and want to select them by name, but the name is stored in a variable.

    Is this possible? Or do I have to write the code for every object?

    As workaround I just added a new "ID" instance variable to compare but im curious if it works without it.

    Or can you use the content of another objects instance variable to select the variable of another object?

    Like this: Dictionary.(OtherObject.InstanceVar)?

    So I dont have to write several lines for every possible entry.

    Like this:

    + Hotspot: SkillLink ≠ ""

    ----+ System: Pick Breadbuilder by evaluating Breadbuilder.ID=SelectedSkillPlanner

    --------+ Hotspot: SkillLink = "Trickster"

    ---------> Browser: Go to Breadbuilder.Trickster in a new window ("NewWindow")

    --------+ Hotspot: SkillLink = "Technomancer"

    ---------> Browser: Go to Breadbuilder.Technomancer in a new window ("NewWindow")

    --------+ Hotspot: SkillLink = "Pyromancer"

    ---------> Browser: Go to Breadbuilder.Pyromancer in a new window ("NewWindow")

    --------+ Hotspot: SkillLink = "Devastator"

    ---------> Browser: Go to Breadbuilder.Devastator in a new window ("NewWindow")

    ----+ System: Pick Outridersbuilder by evaluating Outridersbuilder.ID=SelectedSkillPlanner

    --------+ Hotspot: SkillLink = "Trickster"

    ---------> Browser: Go to Outridersbuilder.Trickster in a new window ("NewWindow")

    --------+ Hotspot: SkillLink = "Technomancer"

    ---------> Browser: Go to Outridersbuilder.Technomancer in a new window ("NewWindow")

    --------+ Hotspot: SkillLink = "Pyromancer"

    ---------> Browser: Go to Outridersbuilder.Pyromancer in a new window ("NewWindow")

    --------+ Hotspot: SkillLink = "Devastator"

    ---------> Browser: Go to Outridersbuilder.Devastator in a new window ("NewWindow")

  • You can add both Dictionary objects to a family, and then either pick by an instance variable, or use this event:

    System Pick by Evaluate DictFamily.ObjectTypeName="name"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, just tried it but I cant find the ObjectTypeName="x". Its not in the list and brings up an error.

  • Type the family name followed by dot, then you should see ObjectTypeName in the list of expressions.

    (It only exists in runtime 3)

  • Its not there for me. AsJson, Count, IID etc. but no object name. I use the latest stable C3.

  • Are you using runtime 3 in your project? If not, this expression will not be available.

  • yes, Runtime is set to construct 3 in advanced project settings. :/

    Do you use a beta build?

    I used the instance variable and could reduce the code to this with a family:

    + System: Pick SkillPlanners by evaluating SkillPlanners.ID=SelectedSkillPlanner

    ----+ Hotspot: SkillLink = "Trickster"

    -----> Browser: Go to SkillPlanners.Trickster in a new window ("NewWindow")

    ----+ Hotspot: SkillLink = "Technomancer"

    -----> Browser: Go to SkillPlanners.Technomancer in a new window ("NewWindow")

    ----+ Hotspot: SkillLink = "Pyromancer"

    -----> Browser: Go to SkillPlanners.Pyromancer in a new window ("NewWindow")

    ----+ Hotspot: SkillLink = "Devastator"

    -----> Browser: Go to SkillPlanners.Devastator in a new window ("NewWindow")

    Thank you very much.

  • Oh, you are right, ObjectTypeName expression is missing for Dictionary or Array objects. This is odd. Reported:

    github.com/Scirra/Construct-3-bugs/issues/4692

  • I see, thanks!

    Maybe Ashley can add this for Dictionary and Arrays? Or is there a special reason why it's not there for these objects?

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