I’m sure someone has asked something like this before but I was unable to quickly find one.
I’m trying to make a simple secret code or sequence a player can execute by moving the character in certain locations in right order. If the player breaks away from the intended code, they must start the whole sequence from the start.
I understand that I must use an array or structure, but I don’t really understand yet how they work and how I can use the events to store my “code input” in that said variable.
There’s 9 parts in my code. Possible inputs are middle, up, down, left and right.
Also, how do I make stuff happen when the code is right? Meaning which events could check whether the code has been inputted successfully.
Thanks. I’ll update if I figure it out!
There is the Konami Code extension and it works with the classic Konami Code (“Up, Up, Down, Down, Left, Right, Left, Right, B, A”). If you install the extension, you can edit the events for it to suit your secret code.
That’s actually very cool, but that’s not exactly what I’m looking for.
You see, I’m not trying to input the code with my keyboard. I input the code by walking around in the map. By stepping on “right tiles”. It’s like a collision thing between objects in a sequence.
Is editing this Konami Code extension still the easiest way to do it?
Your method would be easier for you not the player.
Assign an ID for each cheat code object
Use a counter variable
When the player collides with a cheat object compare the object ID to the counter if it’s equal to the counter then increase the counter
If it’s not equal to the counter reset the counter
If you want to add a timer, start it when the 1st tile is hit
If the counter is like 8 then reset the counter and do something.
You can give the player some feedback after each successful collision like a sound or something.
You might need something so the player doesn’t get penalized for hitting the same tile twice in a row.
I’m thinking about the clichéd booby trap where a brick would sink when stepped on. IDK your scene but a visual clue could be interesting.
If Collison and default animation and ID then increase the counter, change animation
If collision and default animation and not ID then reset counter and all of the animations
That way if the tile has been collided with then nothing would happen on a 2nd collision.
Thank you. This sounds about right.
However, I don’t fully understand how:
I have whole different objects for every cheat code object to identifying them from each other is not a problem I think. But the next part is: compare object ID to the counter. What kind of variable is this counter variable? Just a number? How will the comparison work then (logically)? Keep in mind that the SAME cheat code-object can be used multiple times in the code sequence. So “left” can be both third and eighth input.
Haha, I had a flashback to that worthless scroll Akara insisted on translating, so that I might impatiently slap the cairn stones randomly without reading it.
And on topic Valo, why not do something like that? Don’t reset the whole sequence, for the love of humanity, but just light up each block when they get it right.
That’s different then. I thought you had just 1 code. I would use text then. Each object would have a string variable object ID. I would use just the first letter of the direction. The codes would be in an array.
I couldn’t think of a way that works. So, I kept playing around until it worked. I got a little carried away but I like the challenge. Most of the code is for debugging. I think it’s fairly straight forward. It might use expressions that are new to you. I don’t know. I can explain my process if needed.
try me: the circle is the player and is draggable.
source: (click the green [code] and download zip
I can be optimized. The variable syntax is mostly in the new format where you don’t need the Variable() part as long as you declare the variable first but there’s still a bug where it wants to add text instead of append it. It should be expandable to any letters or any number of code objects just change the ID text. It’s setup for 5 characters but that can be changed.
Edit: I would thoroughly test it.
Oh wow. Incredible. Thank you so much.
I haven’t yet tried to implement that in my game, but your demo seems to work pretty much exactly like I need mine to.
I’ll get to work. With any luck, I’ll be able to translate what you have built into my game with few changes and with a bit of patience.
Thank you again.
You’re welcome. It was fun to make. I love the challenge. Good luck with your project.
I’m still very much a beginner here, so unpacking this is pretty challenging. However I feel like I’m starting to get it. If you don’t mind, I’d like to ask 2 questions at the moment:
What is happening here?
I understand it’s comparing strings? The first part of the comparison is made out of testCode and CodeGroup.ID combined (no spaces or anything, the stings really are just stitched together). The seconds part of the comparison is confusing to me. A substing is just a part of a string I believe, but I don’t really understand it nor the (child, 0,counter+1) after it.
What is the CodeGroup.ID? Where does it get it’s value? Doesn’t it just refer to what ever object from the CodeGroup I touch? I assumed so, but I’m confused because none of the objects seem to have ID value. They have the variable yes, but the value is empty. However it’s clear that when this happens…
…it’s not just adding empty space to testCode. So where does it gain it’s value?
1 is compare 2 strings
The substr is sub string, subStr(string, first position, length)
It’s used to only compare the same numbers= of character as the counter+1.
If the counter is 1 then it checks 0 to counter+1 or 0,2
The codeGroup.ID is an object variable. Each object has an ID variable. You could use the same object. I wanted animations and the smallest number of events. So, I put the different objects into a group.
Even though I didn’t use instances, I set the variable through the instance variable. I don’t know why. It probably made sense at the time. When you’re making things up, you sometimes change strategies.
Edit: child and childIndex come from the for each child They’re the child value and the child index.
Oh right! The ID value is set in the instance variables, not object variables. That clears it up. Thank you again for your time.
This is by no mean necessary, and you have helped me tremendously, but I was thinking: how much these events could be simplified if I had only one code? There could be situations where I only need one.
So if you’d LIKE to solve one more challenge, that could be helpful for a lot of beginners. Having a small demo like this you made, but instead of 5 codes there is only one, could be a great help.
The konami code extension already pretty much does exactly this but I can think of times when it would be nicer to have it in the events - self built - and not as an extension.
I don’t have the time to rewrite it. Some of it is debugging and demonstration. You wouldn’t need all of the different child match id = 0 thru 4 lines. You wouldn’t need to use an array, so you wouldn’t need the for each child It wouldn’t need much.