How do I check several words do not exist in a string

Just started using Construct 2? Post your questions here

Post » Mon Feb 19, 2018 1:32 am

I'm creating a buffer for player input to trigger and prioritize moves. Each button and gamepad direction is assigned a letter which is pushed to the back of an array which is limited in size to (6,1). Every tick I set an instance variable called "Moves" in the array as follows:

PlayerInput.At(0) & PlayerInput.At(1) & PlayerInput.At(2) & PlayerInput.At(3) & PlayerInput.At(4) & PlayerInput.At(5)

I now want to check that this array does NOT contain a specific set of combo inputs (e.g. "ABXY", "XYABX") which may be 4, 5 or 6 letters long, so that I can trigger lower priority non-combo moves

I have tried the following event using the "system compare two values" option:

find(PlayerInput.Moves, "ABXY") = -1 AND find(PlayerInput.Moves, "XYABX") = -1

But this doesn't seem to work. I assume the find expression returns -1 when the string is not found. Is there a better way to do this check? Any suggestions appreciated.
Posts: 11
Reputation: 666

Post » Mon Feb 19, 2018 4:44 am

That condition is correct and it should work.

You can add some debug output (for example Browser->Log PlayerInput.Moves & " " & PlayerInput.AsJSON) to see what's going on.
Or run your game in Debug Mode and check the contents of the array and its instance variable.

Also, there are a few plugins that you can use to detect combos, here is one from Rex:

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
Posts: 2,011
Reputation: 76,603

Return to Beginner's Questions

Who is online

Users browsing this forum: oosyrag and 3 guests