playMaker

Author Topic: Accessing arrays between GameObjects - ArrayMaker  (Read 2174 times)

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Accessing arrays between GameObjects - ArrayMaker
« on: November 28, 2014, 02:56:26 PM »
Hi there,

I'm having trouble getting GameObjects to interact with arrays that exist on separate GameObjects. I tried replicating the setup outside of my main game project in case something there was causing problems, and I can't get my desired behaviour to work even in a very simple project with just a few cubes.

What I'm trying to do is create a jagged array for a 'map manager'. I then need objects to be able to add themselves to this array. I have 2 simple FSMs that are running on very basic GameObjects to try to achieve this.

1. Empty GameObject

This object holds the top level array, and also has empty children which hold the arrays for each row in my 2d jagged array. The top level array is prefilled with the GameObjects for the relevant rows. The FSM on this object simply gets the owner and stores it as a global variable 'map_manager_go'

2. Various Cubes

These cubes each have an FSM that attempts to retrieve the relevant array and then tries to add itself to the array. The FSM on these objects stores itself as a local variable 'local_object_go', then attempts to 'ArrayList Get' the correct row array it's meant to be working with from the 'map_manager_go' global and stores this as a local variable 'local_row_go'. The cube then attempts to 'ArrayList Add' itself as 'local_object_go' to the arraylist on 'local_row_go'.

I can only assume that I'm missing something really simple, because it seems to me like the above behaviour should work - but the initial ArrayList Get appears to fail. I haven't set up a failure event, but if I check the local variables while the scene is running I can see that the 'local_row_go' variable is empty (despite the FSM having moved past that action)
« Last Edit: November 30, 2014, 06:37:27 PM by bfd »

bfd

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Accessing arrays between GameObjects - ArrayMaker
« Reply #1 on: November 30, 2014, 06:44:52 PM »
On further investigation I noticed that the scene I uploaded does seem to work, and the problem is in my own game scene that I'm trying to use it in.

What I've discovered is that the Get Array List actions seem to mostly fail because (I think) there are 36 different GameObjects all trying to get the same array list when the game starts. I've noticed that 4 of them actually work, and it's the same 4 every time, but the rest fail to get the array list (even though the failure action doesn't actually trigger - the FSM seems to think it's retrieved the array list)

I've figured a way I can potentially work around it if needed. The objects I'm trying to build into the array are spawned within a map section quad and are added as children. If needed I can prefill the array with the map section (rather than the generated object) and any time I need to get the object I can find child with tag - but it's messy and I'd really rather build a proper jagged array of the actual objects that I can work with.

Because each object needs to be added a precise location in the array list, I'm leaving the action of adding to the array to the object itself - so each can have a unique FSM pointing the object to the right place in the array. If there's a better way to achieve this so that I can avoid the 'get array list' part of my process then I'm open to suggestion, but I can't see any way to put each object in its correct array list entry without adding from the object itself.