playMaker

Author Topic: Problems adding GameObjects to an ArrayList in ArrayMaker  (Read 1668 times)

stevvers

  • Playmaker Newbie
  • *
  • Posts: 9
Problems adding GameObjects to an ArrayList in ArrayMaker
« on: September 09, 2014, 05:32:08 PM »
Hi guys,

I’m very new to the Game Dev/Playmaker thing, but I like to think I’m learning quickly. What I’m aiming to do here is a little complicated, but I’ll try to explain it as simply as possible.

Essentially I’m trying to create a grid-based star-map procedurally. I’ve managed to get everything working except for the final step of adding each star to an ArrayList for future access. What I have is a number of quads arranged in a grid of 6 x 6, so 36 grids total. Each quad has an FSM that determines the grid’s size and location and spawns a random star-type (from a separate ArrayList) somewhere within that grid.

Because these objects are being generated at run-time, it’s very difficult for me to reference them directly, and I really need an ArrayList that stores each star at an index that matches the grid # so I can access the star object based on where it is in the grid.  I think perhaps this wouldn’t be such an issue if I had a single FSM creating all of the stars, but this system seems much more modular to me – which is important to my development model.

Currently I have a blank GameObject called map_manager_go which holds the ‘Star_List’ ArrayList. The FSMs on each map quad are based on the same prefab, but each has a unique action that sets the current_planet_index_i variable as 0 for the quad MapSection0, sets current_planet_index_i as 1 for the quad MapSection1 and so on. Once the star object has been generated, I’m trying to tell the FSM to add this object to the ArrayList on map_manager_go at current_planet_index_i. I’ve given the ArrayList a unique reference to make it easier to identify, and I have an action that tells the map_manager_go to identify its owner and store it in a global variable so that the MapSection FSMs can easily find it.

All of this seems (to me at least) like it should work, but it doesn’t. I’ve tried using ArrayList Set and ArrayList Insert and neither seems to give the correct outcome (I’m not 100% sure which is correct in this instance, I believe ArrayList Set should be right) I’ve also prefilled the ArrayList with 36 blank GameObjects just to be safe.

Somehow, what I get is only items 5 & 9 added to the ArrayList (and even those two items don’t always add correctly, sometimes adding ‘blank’ rather than the correct object) The ArrayList goes from 36 prefilled objects to 10 rows max.  I also get a massive number of errors thrown: ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count. Parameter name: index

I’m not sure if this is an issue because multiple FSMs are trying to add to the same ArrayList simultaneously. I’m assuming having a single FSM to generate all of the stars would allow me to use ArrayList Add (instead of Set), as the index could increment based on the quad’s grid location, but I really don’t think it’s possible to create the map this way while remaining modular. Sorry for the long post - any suggestions on what I’m doing wrong, or how to achieve this differently would be greatly appreciated.