playMaker

Author Topic: Arraymaker help  (Read 10440 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #15 on: December 14, 2013, 11:12:59 AM »
Ok, I think I've done it using Array List Insert.
So now I get the item from the Array using the correct index, then remove it using that index, then insert.  Makes senses, but looks like I'll have to do that manually adding/removing index numbers into each item.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #16 on: December 14, 2013, 11:20:06 AM »
Ok, its driving me mad.  Inserting does not alter the position of the items.  So item1 at index0 when removed becomes item2.  So my manual setting for each item becomes invalid and doesnt work.
Any ideas anyone?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14126
  • Official Playmaker Support
    • View Profile
Re: Arraymaker help
« Reply #17 on: December 14, 2013, 11:29:33 AM »
Hi,
 
Inserting does alter the position of all items AFTER the index you inserted an onject into. Are you sure you are correctly using the "insert" method?

I think you are overcomplicating things here.

ArrayListGetClosestGameObject comes with two results, the gameobject AND the index.

 So use that index return to know what index to remove from the list. I am not sure where is the difficulty you are facing here. have you tried this already?

bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #18 on: December 15, 2013, 11:56:24 AM »
Hi,
 
Inserting does alter the position of all items AFTER the index you inserted an onject into. Are you sure you are correctly using the "insert" method?

I think you are overcomplicating things here.

ArrayListGetClosestGameObject comes with two results, the gameobject AND the index.

 So use that index return to know what index to remove from the list. I am not sure where is the difficulty you are facing here. have you tried this already?

bye,

 Jean

Ok thanks.  It works great now, I didnt think to look at the index return from the ClosestGameObject.  By the way, is there a way to check if the Array is empty?  I need it because when all items are picked, the NPC needs to move on.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #19 on: December 15, 2013, 01:01:09 PM »
Its ok, I've used Array List Contains.

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #20 on: December 15, 2013, 03:51:35 PM »
Get the ARRAY Count and then do an INT Compare, if Count <= Zero, move on.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #21 on: December 16, 2013, 10:21:30 AM »
Get the ARRAY Count and then do an INT Compare, if Count <= Zero, move on.

Thanks mweyna, I think that'll probably be better for performance? Don't know if there is a way to just check that action against array list contains.

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #22 on: December 16, 2013, 10:58:37 AM »
There is to my knowledge no single action that just returns if an Array is empty or not, you always need to add an INT COMPARE. Nothing about it though should become a beast of a scene. In general though, the less actions you have running per frame, the faster your game will run.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14126
  • Official Playmaker Support
    • View Profile
Re: Arraymaker help
« Reply #23 on: December 16, 2013, 11:08:54 AM »
Hi,

mweyna has a good point here. I have added this to my tasks for the next arrayMaker update:

https://trello.com/c/FamlVQBD/31-arraymaker-update

Now, as for real impacts on performances, you should worry about this IF you are using too many actions or processed within your game loop ( the code and features that are constantly running, like user input and player movements), that's very important, but if you do that based on a button action or something, then this is definitly not as critical.

bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #24 on: December 17, 2013, 08:42:51 AM »
Hi again,
Sorry for another question, my array for the NPC is working perfect, he picks up an item, that item is then removed, then he moves to the next item.
So, now I have my player to also pick up these items in the same array.  It works ok, except when I pick up an item, say item4 index 3, the array is updated but the item at index 0 gets removed and not item4 for example.
I have 2 FSM's on each item.  One for the NPC the other for my player.  And they are triggered each time an item is picked up, which then updates my Array.
I just need to know how I can get the index for the item my player picks up.  The NPC works fine because I use GetClosestGameObject which returns the index, so I use that to remove from the Array. 
So in my player FSM on my item,  I Get Array List, I store the result in a GameObject. Then remove that object from the Array.  And this is where my problem is.  The result just returns the item at index 0, and I need the index to return the specific item the player has picked up.
Thanks for any help.

mweyna

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Re: Arraymaker help
« Reply #25 on: December 17, 2013, 09:20:23 AM »
The problem is kinda based on trying to track things with indexes. In my experience unless your using INT or FLOAT variables, if you're just interacting with gameobject variables you can just use REMOVE and not REMOVE AT INDEX type commands. When your NPC picks up the item, have it remove the Item rather then the index number.

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #26 on: December 17, 2013, 10:19:24 AM »
The problem is kinda based on trying to track things with indexes. In my experience unless your using INT or FLOAT variables, if you're just interacting with gameobject variables you can just use REMOVE and not REMOVE AT INDEX type commands. When your NPC picks up the item, have it remove the Item rather then the index number.

Thanks, thing is my NPC is working fine with REMOVE AT. But with my player, I simply just use REMOVE.  I don't quite understand what happens when I use Array List Get in the stored gameobject.  It looks like it just returns the object at index 0.
It's there no way I can get the index for the item my player picks up?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14126
  • Official Playmaker Support
    • View Profile
Re: Arraymaker help
« Reply #27 on: December 17, 2013, 11:11:07 AM »
Hi,

 Arrays are not very clever, so you need to do that logic yourself really. that is, if you want th eindex of the item your player picked up, you need the reference of that item, and then find it in the array. that's the only way. you could use a hashtable and have item's referenced with strings and when your player pick up an item, you only want that string reference, and then you can get an value straight from a hashtable using that string reference, this is maybe what you are missing in your system, Arrays are good for listing, not necessarly good for refering to items in general.

Bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 258
    • View Profile
Re: Arraymaker help
« Reply #28 on: December 17, 2013, 11:17:46 AM »
Ok thanks again. I'll have a look at hashtables in your samples. Can I still use my array set up for the most part and just use a hash table to reference the items in my array?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14126
  • Official Playmaker Support
    • View Profile
Re: Arraymaker help
« Reply #29 on: December 17, 2013, 11:32:14 AM »
Hi,

 of course, I also sometime use several arrays combined to form a sort of table ( several fields per row).

so if for example several properties you would do this:

index | Weapon name | Weapon damage | Weapon Cost
0         gun                  100                     400
1         riffle                 200                     800
2         bazooka            1000                    2000

and you would have three arrays, each having the proper reference ( name, damage and cost), and so you could have some pretty powerful tables like that without having to resort to a database ( tho, it would be recommanded if you deal with a lot of tables.)

bye,

 Jean