Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Gevarre on May 12, 2014, 01:57:04 PM

Title: Array List Get Next not resetting?
Post by: Gevarre on May 12, 2014, 01:57:04 PM
Hi,
I'm using an ArrayListGetNext action to loop through some things in an array and then using the Finished event to do something else.

This is all working fine, but the trouble is that if I go back to that same action later and use that same ArrayListGetNext again, the second time it just goes straight to the Finished event instead of starting at the beginning again. it's like it's not resetting to the beginning of the list or something, but instead just leaving the pointer at the end where it left off previously.

Is anyone else having this problem, or do I need to do something different?
Title: Re: Array List Get Next not resetting?
Post by: Yanifska on May 13, 2014, 12:39:59 AM
I have been using the Array List Get Next action a lot recently and I havent seen this kind of problem. I have even made a test to see if the action would loop infinitly and it does.
Maybe your array list got empty ?
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on May 13, 2014, 04:23:53 AM
Hi,

 there is indeed a problem, I need to over all of these getnext xxx and insert a boolean variable to force a reset as you renter the state if you haven't fully processed all items in the loop.

 Coming soon :)

Bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: Gevarre on May 21, 2014, 09:04:53 AM
I don't mean to rush you because I'm sure you have a lot going on, but any progress on this?
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on May 21, 2014, 12:45:34 PM
Hi,

 Yes, it's already solved in my local version, I need to push it to the wiki sometime this week.

I referenced it on the trello task, and now it's ticked :)

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

 Thanks for your patience :)

Bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on May 23, 2014, 04:36:59 AM
Hi,

 ok, it's up now, download from the wiki again. Let me know how it goes.

bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: Gevarre on May 23, 2014, 09:47:02 AM
So where exactly would that be? I'm not seeing anything on your wiki page.
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on May 27, 2014, 04:16:24 AM
Hi,

  I mean download ArrayMaker again here:

https://hutonggames.fogbugz.com/default.asp?W715

Bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: Gevarre on May 27, 2014, 09:37:11 AM
Okay, so I re-downloaded and installed Arraymaker, but either I'm confused or it's not working.

In the ArrayListGetNext action I know see the "Reset" item. The tooltip says "Set to true to force iterating from the first item". The trouble is, there is no true or false to set. There is only "None" and "Proceed".

Choosing None doesn't do anything. Choosing Proceed adds a readout box that says "False" by default, but again, no way of setting anything to true.

With either setting it still runs the same as before.
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on May 28, 2014, 09:52:20 PM
Hi,

create a "reset loop" boolean variable, and have a state prior entering this looping state where you set this "reset loop" to true. then the "next" action will use that reset loop, check if it's true, if it force starting index to be 0, and set that "reset loop" to false.

 so everytime you know you exited early a loop, set that "reset loop" to true to make sure it gets reseted next time you enter the loop.

Bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: sebaslive on May 30, 2014, 04:27:16 AM
Did it work? The same thing seems to happen with get next child... I resorted to using get random for both array and child.
Title: Re: Array List Get Next not resetting?
Post by: Gevarre on May 30, 2014, 10:51:28 PM
Unfortunately, I'm still having no luck. Though I'm guessing it's something I'm doing. In the attachment you can see the test setup I did. The Idle state at the beginning is just a gui button to start to sequence. "draw gui text field" just makes a text input box and stores the input in the string "letterFromInput" (which you don't see in this shot).

Once the player inputs text (in this case I just do a single letter), it goes on to ArrayListSearch. The object contains an array of 26 entries, the alphabet. Array List Get Next is supposed to step through each of those entries, passing the current entry on to the "CheckLetter" state, which just compares the string entry in the array to the letter I input at the beginning. If the strings match, it displays them, if not, it goes back to the ArrayListSearch, which should step to the next array list entry.

Unfortunately, with the settings shown here, it never does find the right entry. It just loops until I get the "looped 1000 times" error.

I assume I'm still doing something wrong, but I don't understand what. I was hoping from the original reply from Jean that "insert a Boolean value" meant there would be some kind of checkbox that said something like "always start from first entry" or something like that. I know that sounds lazy, but due to the confusing nature of this setup, it would help make it "idiot-proof" to idiots like me ;D

Anyway, I get that the problem is probably that every single time it iterates, the Reset Boolean gets set back to true, so it never gets past the first entry, but I'm not understanding how to set it up to separate that step. A small working example of this setup would go a long way to help figuring this out.
Title: Re: Array List Get Next not resetting?
Post by: Gevarre on May 31, 2014, 08:24:15 PM
Okay, so I got it figured out and working, at least for ArrayListGetNext. I don't know about the others. It came down to me not thinking correctly on how logic moved between actions. The way I had it, the "reset" variable was set to true in the same state as the ArrayListGetNext action. I was picturing that when it looped back in to check the next entry in the array, it would just go straight to ArrayListGetNext, which, of course, now that I look at it again, it doesn't do. The flow always goes back to the first action in the stack even if an action in the stack is set to some sort of "loop". The way I had it resulted in ArrayListGetNext ALWAYS restarting with the first entry and never getting past it.

So here's the correct way to set it up (This is specifically for ArrayListGetNext. I assume others work similarly):

1. Create a Boolean. I called mine "resetMyArray". Set the default to false.
2. Create a state that contains the ArrayListGetNext action.
3. In the drop-down box to the right of "Reset" select "resetMyArray" or whatever you named your Boolean to.

So now whenever that state is first ENTERED, and "resetMyArray" is true, it will start looping from the beginning again. Now on to the loop...

4. Make another state to do something with the array entry. In my case it's a string array and I'm comparing the individual strings to text that the player inputted at the beginning. I'm calling my state "CheckLetter" in the attached images.
5. Back in ArrayListGetNext, set the "Loop Event" to that new state.
6. Now back in the state that does the comparing, set the false condition to go back to the ArrayListGetNext state. This way it will keep looping until it finds the entry you're looking for.
6. Set the true state in the comparer to move on to a new state that does something with the entry. In my case it's "DisplayLetter" that just prints the entry to the screen.

You now have a setup that loops through an array until it finds what you're looking for and then moves out of the loop to do something with it. (I'm ignoring the "Finished Event" and "Failure Event" for now)

Now for the final step. Once you've done something with the entry, at some point we're assuming you want to start the whole thing over again, looking for a different entry in the same array. The problem is that by default, ArrayListGetNext will pick up where it left off, so if the new entry is before the last one you looked for, it will continue to the end and fail. Jean's new upgrade fixes this.

7. Make a new state. I called mine "ResetArrayPointer".
8. In this state, add a SetBoolValue action. Remember the reset Boolean we made at the beginning? Use the SetBoolValue action to now set that value to true.
9. Now back in the last state you made, the one that did something with your output, add a "FINISHED" event and hook that up to the SetBoolValue state.
10. Finally, add a "FINISHED" event to the SetBoolValue state and hook that up back into the ArrayListGetNext state, and you are done.

Now what should happen is that ArrayListGetNext will initially see the "Reset" Boolean as false and start looping through the array entries. When it finds what you're looking for, it will exit the loop and do something with the entry. After all that's done, it will set the "Reset" Boolean to true, meaning, "Hey, I've finished doing what I needed, now I want to start completely over". The next time the ArrayListGetNext state is entered, it will see that "Reset" is now true, and start at the beginning again!

Anyway, sorry for the length of the post, but I wanted to be sure I gave all the necessary info. Better too much than too little. Attached you will find two images showing how I have things set up. I hope I've made it simple enough that it'll be self-evident how everything should be set up.

Thanks to Jean for his never-ending help. Hope this helps :)
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on June 03, 2014, 05:05:05 AM
Hi,

 :) thanks for this. Indeed I can't really think of another way to have a reset system on an action. The other option would be to create a new set of similar actions where you actually have a variable storing the index, and so coming back to the action always increment the index by one, so you can leave, set the index back to 0 and start again. The issue with this would be that it would have to be a new action to not break compatibility with previous projects using the current get next, and my reset system is backward compatible.


bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: Yanifska on July 28, 2014, 12:32:06 PM
Hi  Jean,
I just tried the new Get Next action, and I got all my previous Get Next action resetted.
The variable and type are empty.
I am fixing it by hand since I need to move on, but you should put some kind of warning.
There is a warning on the wiki page, but you wrote in your last post that it was backward compatible, so it's a bit confusing.
Just wanted to let you know.
bye,
Yaniv

Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on July 29, 2014, 04:58:20 AM
Hi,

 uhm... odd. Sorry about that, indeed I haven't changed the public properties previously setup on that action. So something fishy might have happen.

 what version of PlayMaker are you using in this case? I'll try to repro.

 Bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: Yanifska on July 30, 2014, 10:45:07 AM
I am using version 1.7.7.f6
I finally decided to load a backup of the project and import a renamed version of the get next action so I can use it only where needed, instead of having it affect my whole project.
Could you share a list of other arraymaker actions that may make the same problem ? so I can rename them as well and import the whole package ?
Unless you plan to publish an updated package  ;D
Title: Re: Array List Get Next not resetting?
Post by: jeanfabre on July 30, 2014, 11:29:37 AM
Hi,

 I'll study the differences, and rename the new action if necessary ( which sounds like it...)

Bye,

 Jean
Title: Re: Array List Get Next not resetting?
Post by: fromfame on May 13, 2019, 02:56:06 PM
Hi jean,

There is a problem with the array script.

In the same state, If there are two 'Get Next Array' actions. The second action's index doesn't go next.

I can't solve this issue as there's something with the script that stops the second action from working if its in the same state.

Would appreciate assistance please.
Title: Re: Array List Get Next not resetting?
Post by: djaydino on May 14, 2019, 09:11:43 AM
Hi, 2 get next actions in 1 state will not work.

You can get the index and the use array get, if you need to get the same index.
or do the 2nd get next in the next state.
Title: Re: Array List Get Next not resetting?
Post by: fromfame on May 14, 2019, 11:41:40 AM
Hey, I've uploaded the test in a video.

Title: Re: Array List Get Next not resetting?
Post by: waveform on May 14, 2019, 04:28:38 PM
Hey, I've uploaded the test in a video.


Try right click on some empty position in state panel then toggle on Action Sequence, this make states finnish step by step,that means next state will not active before previous state finnish