Create object by name with a string?

0 favourites
  • 8 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I'm using xml files as maps. I would like to create objects based on xml tags. Currently, I seem to have to read in a line from the file and then have a condition for every different kind of object which exists and then create that object.

    Here's a crude psuedo code version of the events:

    for each node in xml:

    if = "skeleton":

          create skeleton

          set xlocation

          set ylocation

    if = "hippy":

          create hippy

          set xlocation

          set ylocation

    I would prefer to do this is a dynamic fashion:

    for each node in xml:

    createObjectByName "skeleton"

    set xlocation

    set ylocation

    Is there a way to do this in Construct 2?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's the similar thread with some work arounds:

    but, as far as I understanf it's not possible and I'm missing this functionality badly.

  • This issue is really wourth the attention. I am aware of 3rd party plugin that does this, but this should be a natural part of C2 - not a plugin.

    So bump

  • There's a reason for that. Read the thread xoros mentioned and you'll understand why.

  • The best you could do is create a function that contains all the objects creation events in a giant "if else" statement. And then you use family instance variables to store your attributes. Here's a rather silly example.

    Note that objects are created during the "pick by uid" condition, which is quite twisted to say the least, but I saved a sub-event doing that.

  • It makes sense that part of the obfuscation process is wrecking all the object names, and I'm actually grateful for that feature. I think though that being able to store some kind of object name hash would be nice. I have been trying to save/load my inventory items between layouts, and it is giving me a bit of trouble. I worked out how to serialize, store the string in an array and setFromJSON, but it looks like setFromJSON requires that the item be spawned as the correct type to begin with. I have Items as a family, not an object type because I am expecting to have dozens or a few hundred items, each with different behaviors and events.

  • bladedpenguin

    Try this plugin - nickname to create object by name string.

  • omg you have as much useful stuff as native C2.

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