Spawned Copies of Sprites

Get help using Construct 2

Post » Sat Feb 02, 2013 10:14 am

Hi all

New to Construct (and game authoring) but have gone through the faq, manual and forum looking for an answer to this.

I have a sprite "Carn" to which I assign values to variables during runtime, not in the layout. Once this instance has enough health & energy I spawn a new instance of Carn.

At present, the new instance selects the default variable values from the layout. I would like it to inherit its parent's values.

Secondly, after the spawn action in the same event, if I select Carn.UID it gives me the UID of the parent, not the child.

This picture might make it a bit clearer:



Any help would be much appreciated.
Thanks
B
5
Posts: 19
Reputation: 363

Post » Sat Feb 02, 2013 10:35 am

Save the parent UID in a local variable before spawning the new object, this way you can refer to it with 'pick UID with variable_here' condition. Depending on how many variables we are talking about it might be simpler to save the variables themselves into local variables before spawning the object and then assign them from the local variables :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Feb 02, 2013 10:49 am

Thanks for the reply, vee. For inheritence, I could individually assign each variable to the child object (although there are 30+variables) but seems a reasonable solution. However, I still need to identify the child UID. I thought this would be populated by NewUID=Carn.UID but that picks up the parent.
B
5
Posts: 19
Reputation: 363

Post » Sat Feb 02, 2013 12:22 pm

This could work: save parents uid into variable of the child (var_parent). Now you can do cool stuff like pick every child of certain carn with event like this :

carn.var_parent = parentcarnUID
.. Set variables to same as parent

After you create new,object in construct it is picked automatically. If You created it from same object id guess they would both be picked. You Can browse them using iid(number of selected instance after name)

carn(0).uid = parent uid
carn(1).uid = child uid
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Feb 02, 2013 12:52 pm

Cheers! Will definitely use the first bit for inheritance.

The second bit returns some odd results for me - I think I need to look at how I'm spawning.

The actual parent and child UIDs are 73 and 280, however I get the following:

carn(0).uid = 5 (shrug)
carn(1).uid = 73 (parent ID)
carn(2).uid = 279 (child ID minus 1)

Would UIDs typically be incremental (1,2,3,4...)?
B
5
Posts: 19
Reputation: 363

Post » Sat Feb 02, 2013 1:27 pm

Uids would be Id assigned at creation, its number assigned to every object at creation. Yes, incremental like you said, bit if you create object_rock and it gets uid 13, if next object created is object_tree it would get uid 14. So uids are not object specific but shared between. All objects.

iids on other hand are ways to browse list of selected objects. If you have picked 5 tree objects you could refer each one with rock(0), rock(1) etc.

In your case it seems that there are more than two objects selected. Try what this returns: carn(pickedcount-1).uid I imagine that might be the uid of the last selected object which should be the one created. :-)
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Feb 02, 2013 2:42 pm

Thanks once more. Definitely getting somewhere (and learning plenty). One remaining oddness I have is that carn.pickedcount = 1 for all instances, even though I have multiple instances in action. Occassionally I see it rise to 2 then immediately drop back to 1.
B
5
Posts: 19
Reputation: 363

Post » Sat Feb 02, 2013 3:30 pm

Object.Pickedcount gives you the amount of instances of the referenced object that are currently picked, meaning, how many instances of object your actions affect. With object.pickedcount 2, you currently have 2 objects picked and so doing 'object.variable = 1' would set that variable to 1 for both of those objects.

If you are seeing pickedcount = 1, then you only have single instance of the object picked. Picking is the thing I had hardest time grasping with C2, it is really powerful tool when you learn to use it properly! :)

Hope this helps, it's hard to say where the problem exactly is in your case without seeing the .capx of your project :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Sat Feb 02, 2013 4:28 pm

You've been a great help!

The spawn is created in a For Each loop so I guess it makes sense that pickedcount shows as 1. Where it spawns that must increase it to 2 until it passes through the loop and reverts to 1.
B
5
Posts: 19
Reputation: 363

Post » Sat Feb 02, 2013 4:32 pm

Just one other thing, is there a way to identify the total number of instances spawned for an object. If I can get the total number of IIDs, I can select the last one as the child and the penultimate one as the parent.
B
5
Posts: 19
Reputation: 363

Next

Return to How do I....?

Who is online

Users browsing this forum: Colorfish and 28 guests