playMaker

Author Topic: Arraymaker help  (Read 10756 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Arraymaker help
« on: December 06, 2013, 11:11:20 AM »
Hi,
I'm currently using boolean checks for items that are distance checked and the closest is set as the destination for my NPC so he goes over picks up the item, checks other items if they are still available, if they are, get the closest distance and set new destination.
I'm thinking even though this way works, Arraymaker is probably more efficient for this kind of thing, so I've set about putting my game on hold and to study the array samples Jean has made.

So, can someone tell me if this is the right way to do this -
1. on the items, Array List Add each one into an array, then listen for the NPC with a trigger.  When triggered, Array List Remove from the array
2. Get the distance to the items that are available in the array.

I know theres more to it, but I'm on the right track, yes?



Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #1 on: December 09, 2013, 10:50:29 AM »
Jean?

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #2 on: December 11, 2013, 08:23:33 AM »
<bump>

Sorry, but looking at the Arraymaker samples, (the cube distance one) that seems to be kind of what I'm after.  But it has 3 temp arrays, I understand how each state works in the 2 FOR EACH loops, but can someone give me a bit of help on what I'd need for what I'm trying to do?
I'm thinking pretty much what I said earlier, but in the FOR loop is that where I'd add in my items (which are dynamic i.e either they are in or out of the array)
then iterate through each time getting the distance to each item and setting the destination to the closest one.
Is that the only loop I would need?

Thanks for any help!

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #3 on: December 11, 2013, 09:27:12 AM »
You have it pretty well sorted out as to how to do it.

So you'd need a loop on the NPC to basically, get the array count, get the item at Position i, check distance relative to the NPC, and then go to the closet one (either through the Closet Action or using your own distance sorting FSM). Then I'd have an FSM on the item itself that the NPC would send an event too when they pick them up with an ARRAY REMOVE function so the item disappears from the list. The FSM on the NPC would then reset and find the next closet one.

As for additional loops and functionality, it depends on performance and what you're trying to do. What you describe is a fairly cheap performance thing to add, but it will have a minimum cost since the loop is always running. You can build in some delays, so if Position i is equal to the Array Max Count in the INT Compare, Wait 3 seconds, etc. All depends on what you're trying to do with the game itself.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #4 on: December 11, 2013, 12:26:11 PM »
Hi, thanks for you help.
I just have a little problem.  I have the array FSM and the array ref on the NPC. And another FSM on the pickup item.  When I try to use something like Array List Remove for example, I have no reference in the Set Up to my array on the NPC.
So I made it a global, so I can now reference it, but I get the same problem with the Data Type/Variables.  How do I reference my items that are sitting inside the NPC array?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14388
  • Official Playmaker Support
    • View Profile
Re: Arraymaker help
« Reply #5 on: December 11, 2013, 12:39:37 PM »
Hi,

 Sorry for the late reply, and thanks mweyna to step in, much appreciated  that share back your experience :)

You are on the right track indeed, and mweyna advices are spot on.

bye,

 Jean

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #6 on: December 11, 2013, 01:33:11 PM »
Two paths, you can either just manually type in the Reference Name "NPC_Item" or do what you did and use a global string variable. On the Array List Remove action for "Setup" specific the Object. You can get that through a Mouse Action (making it the hitObject), or a variety of ways. Targeting Arrays on other items is much the same as targeting anything else on other items. You define what Game Object is holding the Reference and then you can interact without issue.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #7 on: December 11, 2013, 01:57:12 PM »
Two paths, you can either just manually type in the Reference Name "NPC_Item" or do what you did and use a global string variable. On the Array List Remove action for "Setup" specific the Object. You can get that through a Mouse Action (making it the hitObject), or a variety of ways. Targeting Arrays on other items is much the same as targeting anything else on other items. You define what Game Object is holding the Reference and then you can interact without issue.

Hi, thanks again for your help :)
I have used the specify game object to the object that holds the array, but the reference just says "none" even though the array is there with a reference.
But like I said, a global fixes that.  But I still dont understand how under "Data" in Array List Remove I can use a GameObject variable that is populating my array in the NPC?
It either says "none" or ask for me to drag on the object.  But I dont want to specify just the one item, I want to use the items variable that is in the array. Does that make sense?
Again, thanks.

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #8 on: December 11, 2013, 02:34:45 PM »
The Array List Remove command just tosses whatever data you specific tossed. So you'd need to use the "Array List Get" function, store that into a Game Object variable, then plug that back in under DATA as the Game Object variable. You have a few choices of how to remove things, either at a specific index, or that specific item way. Either way with that Game Object now defined, it should properly be removed. If you want to remove an entire array of contents, you can always use the "Array List Clear" function.

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
    • View Profile
Re: Arraymaker help
« Reply #9 on: December 12, 2013, 03:00:36 AM »
Hi,

from my experience u want to keep the inter object relations and dependencies as simple as possible. So the pickups should actually only know they are "pickups" aka have a layer/tag or component with a IPickup interface. They should not fiddle with the logic that decides or filter when and what to pickup.
So using the "FindClosest" action in your Ai FSM is totally valid and i would always prefer this over adding more dependencies between the Ai and the Pickup.

As a rule of thumb, if "some" task/logic don't needs to-be done per frame and can be easily delayed/spaced out, don't premature make a system more complex because it "might" be more efficient.

bye Andy

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #10 on: December 12, 2013, 12:30:42 PM »
Ok thanks for your help.  I'll keep that in mind Andy, sounds good advice. 
Looks like the array is working fine at the moment.  Just going to test.  And test some more before I move on :)

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #11 on: December 13, 2013, 12:18:17 PM »
Ok, small problem, I'm using an item array and a temp distance array.  When I get the distances, they are sorted in the index, the smallest is always at index 0, for some reason.  So which action do I use to get the smallest float that is index (0) and store it as a Gameobject so I can then use it to set the destination of my NPC?

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #12 on: December 13, 2013, 01:47:18 PM »
Why not just use "Array List Get Closest Game Object" from the original Item Array? It should automatically return the closet item so you don't need to do any distance sorting yourself.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #13 on: December 14, 2013, 10:46:22 AM »
Why not just use "Array List Get Closest Game Object" from the original Item Array? It should automatically return the closet item so you don't need to do any distance sorting yourself.

Ok, thanks for you help again.
That works now, but on closer inspection of what is actually happening, the incorrect item from the array is being removed on pick up. 
In fact, I had the item FSM set up wrong.  I had something like -

On trigger enter >
Array List Get (which was picking up an item at index 0) >
Array List Remove (which removed the wrong item because it was always going to be at index 0)

So, I cant work out how to remove the item from the array that has been picked up. I need to somehow get the items that are in the array (say item1, item2, item3) at index 0,1,2 and if item2 is picked, that item from the array is removed, i.e index 1.
Any help?


Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #14 on: December 14, 2013, 11:06:55 AM »
When I use Array List Get before I want to remove the item, in the At Index, if I add in the correct index for that specific item, so say item2 is index 1, then it works, but then because when index 1 gets removed, item3 then moves to index 1 so obviously it doesnt work then.
I need to somehow have the index set so when one gets removed, it gets added back at the same index.  Maybe thats the way, or is there an easier solution?