Create object by name with a string?

Get help using Construct 2

Post » Tue Sep 11, 2012 8:03 pm


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 node.name = "skeleton":
      create skeleton
      set xlocation
      set ylocation

if node.name = "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?
B
17
S
3
G
6
Posts: 14
Reputation: 3,850

Post » Tue Sep 11, 2012 8:34 pm

Here's the similar thread with some work arounds:

http://www.scirra.com/forum/how-create-obj-by-name_topic50394.html

but, as far as I understanf it's not possible and I'm missing this functionality badly.
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Wed Jan 07, 2015 12:29 pm

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
ImageImageImageImage
B
26
S
7
G
7
Posts: 572
Reputation: 6,097

Post » Wed Jan 07, 2015 4:31 pm

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

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
15
S
3
G
1
Posts: 329
Reputation: 2,002

Post » Wed Jan 07, 2015 5:09 pm

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.
You do not have the required permissions to view the files attached to this post.
B
46
S
17
G
18
Posts: 846
Reputation: 13,800

Post » Thu Feb 26, 2015 7:11 am

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.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536

Post » Thu Feb 26, 2015 7:14 am

@bladedpenguin

Try this plugin - nickname to create object by name string.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Fri Feb 27, 2015 3:37 am

omg you have as much useful stuff as native C2.
B
14
S
5
G
1
Posts: 189
Reputation: 1,536


Return to How do I....?

Who is online

Users browsing this forum: Magistross, mallorcaredes, zatyka and 24 guests