How do I Spawn Objects From an Array

Get help using Construct 2

Post » Sun Oct 19, 2014 4:51 am

Hey guys, I am working on an RPG and I had an idea to spawn objects on the board from an array. The reason I am doing so is so that I can create a dynamic environment where the PC can pick items up, move objects around, drop items, destroy objects, etc., and I wanted to track those changes in an array so that when the PC returned to a previous layout, those changes were still present. But I'm also going a step further and having the program move or remove some items around (so a PC might return to find that some objects have been removed or returned to their original positions, but some impact might still be noticeable).

Anyway, I wrote a function to spawn objects from an array when the layout is loaded. It stores the name of the layout the objects should appear on, the coordinates of the object, the ID (a variable I've added to the family "Items" which is used to select the item to spawn), and other information that isn't being used yet but I plan to include once I can get this running. I've run tests to ensure that the array was loaded correctly (data is being imported from a csv file) and that the variables are pulling the right data from the array. So far that all checks out. However, the objects that are spawned appear to be completely random. They do appear at the right locations, but I can't seem to get the function to select the right object to spawn.

Am I missing something obvious here? Or is there an easier way to go about this?

Construct Screenshot.png
You do not have the required permissions to view the files attached to this post.
B
2
Posts: 7
Reputation: 164

Post » Sun Oct 19, 2014 5:24 am

Creating Family objects always produce a random object. You need to decode and create the specific object.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sun Oct 19, 2014 5:28 am

Or you can create an instance variable for the family and create FID (family ID) then give a condition which choose the specific FID to be spawn.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sun Oct 19, 2014 3:58 pm

blackhornet wrote:Creating Family objects always produce a random object. You need to decode and create the specific object.

Is there a way to do that without a lot of "If" statements to select a specific object? I was trying to choose a specific object based off of the Index variable.
B
2
Posts: 7
Reputation: 164

Post » Sun Oct 19, 2014 4:02 pm

DuckfaceNinja wrote:Or you can create an instance variable for the family and create FID (family ID) then give a condition which choose the specific FID to be spawn.

Thanks. That's what I was trying to do with the Index variable. That variable is different for each object type and I was attempting to pick the object to spawn by using that variable. Can you help explain why my condition to pick the object isn't working? I have checked the variable in my test runs and the ItemIndex variable is filled correctly, but it isn't picking the object with the corresponding Index value.
B
2
Posts: 7
Reputation: 164

Post » Sun Oct 19, 2014 4:45 pm

bonenaga wrote:Thanks. That's what I was trying to do with the Index variable. That variable is different for each object type and I was attempting to pick the object to spawn by using that variable. Can you help explain why my condition to pick the object isn't working? I have checked the variable in my test runs and the ItemIndex variable is filled correctly, but it isn't picking the object with the corresponding Index value.

Ah my bad. I forgot that you can't pick an object that is not created yet. I think you have no choice other than using an "if" for each family member.

I think it could be a good suggestion to Ashley to introduce FID (family ID) into C2. This will enable object creation control in the family.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Sun Oct 19, 2014 5:03 pm

ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Sun Oct 19, 2014 7:05 pm

Thanks a lot for the replies guys. I'm going to look at the nickname plugin and see if that will help out.
B
2
Posts: 7
Reputation: 164


Return to How do I....?

Who is online

Users browsing this forum: Blendi1223, jatin1726, Kyatric and 24 guests