playMaker

Author Topic: Referencing GameObject from Array (ArrayMaker)  (Read 1889 times)

adentutton

  • Playmaker Newbie
  • *
  • Posts: 9
Referencing GameObject from Array (ArrayMaker)
« on: May 09, 2016, 10:55:36 PM »
Hi guys

I have created an array for the players positions in a sport sim game. In Volleyball  each player will have certain spots they move to depending on what position they are currently in. Is there a way to directly reference the GameObject from the position they are currently in in the Position Array? (e.g. In a specific point can I directly make the GameObject (whoever that currently is) in position 3 move to a certain point on the court or to I have to find that GameObject and then store it in a new variable for it then to be accessible to move?

Thanks!

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Referencing GameObject from Array (ArrayMaker)
« Reply #1 on: May 10, 2016, 02:55:02 AM »
Hi Dude,

You can use the action "Array Set" to change the values in your array directly if you know the index.

If you have an array of gameobjects, their position should be automatically updated in the array without you needing to change anything. As you are referencing the gameobject, it will store information about its position, scale, rotation etc. You can then use the action "Array Get" to get whatever info you want from that gameobject.

But if you just wanted to edit something in an array directly you can, its like an override feature though.

Is this what you are after?
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

adentutton

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Referencing GameObject from Array (ArrayMaker)
« Reply #2 on: May 10, 2016, 05:00:03 AM »
Thanks for the reply!

I was just looking to see if it was possible to directly reference the Array index when creating using an action such as "Move Towards". So that instead of creating my array with all of the players in position and then have to use the "Array Get" action, put it in a seperate and new variable and then choose which position to move the GameObject in the relevant position. If this were the only way it wouldn't even be helpful to have the playing positions in arrays but instead as seperate variables (e.g. position1teamA) if I constantly have to get the value from the array?

Thanks again for your help!

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Referencing GameObject from Array (ArrayMaker)
« Reply #3 on: May 10, 2016, 09:39:46 AM »
Hi dude,

I read this a couple of times and thought about it. So hopefully I got it right.

What you can do is break it down a state into 2 parts/actions.

The first action retrieves a reference to the gameobject directly: if you know the index of the player, maybe use a naming convention and have them order to match in your array.

The second action would then apply where you want the player to be. You could then return to this state or have a global event on top of it. So maybe the players index is a global variable that you update and then call that FSM to move the players position.

I have attached a screenshot of what I mean. I hope it makes sense. I think it would work and should keep things clean. Would just require the use of a couple of global variables to finish off the logic:

player index
player move position
« Last Edit: May 10, 2016, 09:42:56 AM by joduffy »
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith