URGENT: key is released overrides following conditions

Hi guys,
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

Farid

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:

  1. Group all the objects that are shown/hidden.
  2. 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).
  3. Create a single variable to determine which phase of the process you are in, in this case, ‘gameRound’.
  4. 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).
  5. 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.
  6. 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.

1 Like

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:

2 Likes

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 :stuck_out_tongue: ) Anyways, I will make the code better after tomorrow.

Cheers

Farid

2 Likes

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.

1 Like

Hi Stelios!
Thanks for your advice/support. BTW, I haven’t forgotten your email, I’m just having to much to do right now :slight_smile:

Cheers

Farid

1 Like

Update:
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.

https://posh.se/youtube_quiz/index.html

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!!

//Farid

2 Likes

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)

Thanks Erdo,
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.

Cheers

Farid