playMaker

Author Topic: Arraymaker: How to replace a Gameobject at a specific index?  (Read 1959 times)

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Arraymaker: How to replace a Gameobject at a specific index?
« on: March 06, 2015, 10:59:08 AM »
Hello fellow Playmakers,

I have had some great success using Arraymaker, but have run into a problem that I'm having a hard time solving:

I have actions that add and remove gameobjects to a list as certain actions are performed.

In some circumstances, I need to replace the gameobject at a specific index with another gameobject.

For example, let's say I have a list that looks like this:

Item 0: GameObjectA
Item 1: GameObjectA
Item 2: GameObjectA
Item 3: GameObjectA
Item 4: GameObjectA

I want to replace the gameobject in Item 3 with GameObjectB, so it would look like this:

Item 0: GameObjectA
Item 1: GameObjectA
Item 2: GameObjectA
Item 3: GameObjectB  <--
Item 4: GameObjectA

I appreciate any help, and will reply with results.

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker: How to replace a Gameobject at a specific index?
« Reply #1 on: March 06, 2015, 02:06:40 PM »
Hi,

 For this you use the action "ArrayListSet". you target the arrayList proxy, you give the index and the value to set at that index.


 Bye,

 Jean

ToxicFrog

  • Beta Group
  • Full Member
  • *
  • Posts: 139
Re: Arraymaker: How to replace a Gameobject at a specific index?
« Reply #2 on: March 09, 2015, 02:59:06 PM »
I must be doing something wrong.

Here's what I've got:

"Seq" is an int, the number of tiles in play
"Seq-1" is also an int that I use to specify the index I wish to modify the contents of

"Swapper" is a gameobject that I want to replace in the list

Here's the sequence I've got:
1. Set Int Value of "Seq-1" to equal "Seq"
2. Int Add -1 to "Seq-1" (so now it will specify the next-to-last index in the Arraylist
3. Array List Set. Use Owner, in the proper Reference, at Index "Seq-1". Data type "GameObject", variable "Swapper".

Yet when I look at the ArrayList, it has not inserted "Swapper". Instead, it shows GameObject (none).

Thoughts?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Arraymaker: How to replace a Gameobject at a specific index?
« Reply #3 on: March 16, 2015, 03:28:59 AM »
Hi,

 you'll need to double check few things:

-- are you properly targeting the right proxies? if you have several arrays or hashtable in one gameobject, you must use unique "references" else it picks up the first one

-- if it's a prefab, are you sure the instance properly host the pointer to gameobjects in fsm variables? remember you can't keep a pointer to a gameobject in a prefab, it will get lost.

-- if you are in the same array ( if you want to swap two items in the same array), then be careful that you don't get mixed up with keeping track of the variables, make sure you have 2 variable, one hosting the value of first index and one the value of the second index, then you can do the deance of swapping.

 I am doing this a lot, so I am 100% sure this works, make sure you go over the process step by step first in your fsm, put  a breakpoint as well on key states, that will help.

 Bye,

 Jean
Bye,

 Jean