playMaker

Author Topic: quick arraymaker question  (Read 1703 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 268
quick arraymaker question
« on: March 18, 2014, 01:11:34 PM »
Hi,
If I add an item into an array on every iteration of i, also removing the last one before a new one is added, will the length of the array be 1, or will the length equal to the value of the index number?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: quick arraymaker question
« Reply #1 on: March 19, 2014, 05:04:11 AM »
Hi,

 yep, you will get a clash between the index and i.

i        -> 0 1 2 3 4 etc
index -> 0 0 0 0 0

what woul dbe the use case of looping trhough swaping the same index? that doesn't make sense?

are you trying to do a first in first out or something?

bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: quick arraymaker question
« Reply #2 on: March 19, 2014, 12:16:07 PM »
I just want to add one in and maybe keep it to a max of say 3, then remove the 1st index.
Basically it's just 3 ints 1,2,3 that are entered randomly so I want to keep on top of the length and also is it possible to only allow non duplicates to enter? So there are none of the same 3 ints going in one after another?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: quick arraymaker question
« Reply #3 on: March 25, 2014, 12:31:55 AM »
Hi,

-- removing the first index is easy, simply delete at index 0
-- keeping a maximum of 3 is also a matter of checking first the number of items using arrayListCount action


non duplicates is going to be a little more tricky... typically I would go for a second arrayList acting as a source to pick random values, let's call it "pool".

"pool" content is:
0,1,2,3,4,5,6,7,8,9

-- now you pick a random item from it, store the value AND it's index
-- then add this picked value to the arrayList target and DELETE from pool that value using the index you picked
-- IF you want to delete an value from the arrayList target, store it first and add back to the "pool", so that you can pick it up again next time.

 Does this all make sense?

bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: quick arraymaker question
« Reply #4 on: March 25, 2014, 03:29:33 PM »
Yes thanks again Jean.