How do I Spawn Objects From an Array

0 favourites
  • 8 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • 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?

    [attachment=0:2f08gvh7][/attachment:2f08gvh7]

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Creating Family objects always produce a random object. You need to decode and create the specific object.

  • 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.

  • 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.

  • 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.

  • 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.

  • You can use the Nickname plugin.

  • Thanks a lot for the replies guys. I'm going to look at the nickname plugin and see if that will help out.

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