Compare the contents of two lists for equality

drhayes

  • Posts: 3
First time poster, brand new Stencyler. Hi there! ( =

I'm working on a combo system. The player presses four controls in a row (e.g. up, up, up, jump) and then something happens.

The way I'm implementing it now is I have two lists as attributes in an Actor behavior: one for the required moves and one for the recent moves. In the updated block of my behavior I check if the controls I'm interested in have been pressed and, if so, add them to the end of the recent moves list. If the length of the recent moves list is longer than the required moves list then I remove the first element of the recent moves list.

My problem is that I have a block that reads "if moves list = recent moves list" that doesn't seem to be triggering even though I know the two lists are equal in content. Does Stencyl not do list equality by content? If not, any suggestions?

I'll take suggestions for how to make this more general, too. I couldn't figure out how to change text (e.g. "up") into a reference to a specific control. I'd love to have a custom block that reads (more or less), "if actor does these moves then..."


Photon

  • Posts: 2691
A suggestion that comes to mind for me is that once the recent moves list becomes full, every time a new action is added, loop through the two lists of items and check for equality. In other words, do both item 1's equal each other, do both item 2's equal each other, etc.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

Tuo

  • *
  • Posts: 2469
I personally would do it as a text for the current moves and a list for the combos. It makes things easier to check IMO. I also like to use a delay instead of a max number of moves (Using a delay of 50 means the keys need to be pressed within a half second of each other). I agree with making things more general too, as you will see with the coding I made up for you (NOTE: the "+"s are TEXT additions, NOT number additions). I've tested it and it works.
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

drhayes

  • Posts: 3
Ah, excellent, thanks for the code, Tuo!

My next step was going to be to enforce a time limit and you've gone and done my work for me. ( =

I like your approach of breaking it down into an event, as well.

drhayes

  • Posts: 3
For anyone following along at home, I took Tuo's code and broke out the combos and their corresponding events.

The behavior, in the end, takes a Duration (Number), a list of Combos (Text, each move separated by a comma), and a corresponding list of Events (each a Text).

Just like in Tuo's solution, the behavior accumulates the keypresses in a hidden attribute. It then compares the value of the hidden attribute against each text in the list of combos and, if it matches, triggers the corresponding event.