I have a deadline tomorrow and nothing works as it should. I want the user to be able to release the same key twice with different results. Like: First time pressing num1 hide a few objects. Next time Show a new object. Problem is that it shows the new object at the first release. Event though I have tried to prevent it with additional conditions.
What am I doing wrong and how can I solve it?
Thanks in advance
You say that you want some objects to disappear the first time you press/release a key, and a different object to appear when you press/release it a second time. However, what your events are doing is hiding all the objects at the beginning of the scene (because the scene starts with gameRound having a value of 0), and when you press/release the key for the first time, those objects appear instead of disappearing. It also sets gameRound, stopKey, and showSign to 1, which immediately creates the second object in the next event. In other words, when you start the scene, no objects are visible, and when you press/release the key, they all appear at the same time, right?
You have a flow issue. My recommendation:
- Group all the objects that are shown/hidden.
- Instantiate each object that needs to be hidden/shown in the scene (you can do this at the beginning of the scene using events or in the scene design window, but remember to hide all the objects using events at the beginning of the scene… except for the object that should be shown initially).
- Create a single variable to determine which phase of the process you are in, in this case, ‘gameRound’.
- Create a single condition to check if the num1 key was pressed/released. When this is true, hide ALL objects in the group and increase the value of ‘gameRound’ (optionally, you can set a maximum value in another variable, so that when it exceeds the maximum value, the value of ‘gameRound’ resets to 0, allowing you to iterate through the process multiple times… if that is your intention).
- Create conditions to check the value of ‘gameRound’. These conditions should be nested as sub-events of the condition that checks if the key was pressed/released.
- Show the right object based on the current value of ‘gameRound’ in each of these conditions.
This way, when you press/release the num1 key, you hide any visible object in the group and immediately show the next object, iterating trough them. Note that you only need one variable, ‘gameRound’, to achieve this, and perhaps another one (‘gameRoundMaxValue’, for example) if you want to iterate continuously through multiple objects.
The key released stays true for (at least) the frame it’s occurred in. So the problem, as @erdo described, is that the first num1 key release actions create the right conditions for the second num1 key release event to be actioned.
Fix it like:
Wow, A BIG THANKS @erdo and @MrMen!
That makes sense. I didn’t know that the key released stays true for the entire frame it’s occurred in. Since I only have until tomorrow to fix this, I have made a pretty ugly solution for the time being (by switching scenes at every key released = a lot of scenes ) Anyways, I will make the code better after tomorrow.
Hi Farid. You could also try to use a flag (variable) to track the state, e.g. when the key was released. Then in your events you will check for the key released and flag status. Based on the flag status you choose what actions to perform.
Thanks for your advice/support. BTW, I haven’t forgotten your email, I’m just having to much to do right now
I made it! The game is a quiz for a YouTube event in Sweden tomorrow. The game can only be controlled with three physical buttons (that generates key strokes) that are 1,X and 2. It’s in Swedish, so I guess no one here understands the questions but you might want to have a look.
Siince I was in a hurry I chose to put every question in its own scene, to be able to handle multiple keypress. Not an elegant solution, but I will make a better version soon, built on what you guys have told me. Thanks for your help!!
This is a extremely simple math quiz example I made last year. It uses a single scene, maybe it’s useful for you: Simple math test (randomized with multiple answers)
I have downloaded the project and will look at it later. In fact, I’ve done a number of quizzes with just one scene, but what was special about my last quiz was that the player can’t use mouse, touch or keyboard. Just three buttons.