ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator Can't Use "Key Pressed Down" for Toggling Between Two Different Actions
person icon
sebastianos
Registered User
Quote
2019-06-02 10:21:54

I have done tests to prove this and you can too. Guys, these issues are NOT GOOD and someone needs to address this. Please take the time to carefully read this.

Alright, so let's use Escape as an example key. And this behavior is tied to the scene, NOT to any objects or overlays.

Situation One
So when Escape "Key Pressed Down", if Box (variable) equals 1, make 2D Overlay1 invisible and 2D Overlay2 visible and set Box to equal 2.

Situation Two
Now when Escape "Key Pressed Down", if Box (variable) equals 2, make 2D Overlay2 invisible and 2D Overlay1 visible and set Box to equal 1.

So the result should be that you can switch back and forth between making the 2 overlays visible and invisible. But IT DOESN'T WORK!! Why? Because CopperCube has this ridiculous issue where just pressing the Escape key once will change the variables of both situations before anything is made visible or invisible. It's like, it reads situation one where Box equals 1 and changes the variable Box to equal 2 and then since Escape is still pressed down, it reads the situation two and now that Box equals 2, it makes variable Box equal 1..... all before getting to making things visible or invisible. At least, that's one of my theories. I don't really know. OR, maybe it's reading situation one, changing the variable AND making one box visible and the other invisible, then since the Escape is still pressed down, it then reads situation two and changes the variable AND makes one box visible and the other invisible. Perhaps both situations are happening so fast that you can't see it or the computer can't keep up fast enough to show it, or maybe it's so fast that it's not even told to draw these things at all on the screen! I don't know, but that's my other theory.

Either way, I think the issue has to do with the fact that the Escape key is pressed down and some or all of both situations are being read at the same time because the Escape key is pressed down for both. Is this a bug with CopperCube? Or is this expected and I should find a different way to accomplish this?

Alternative Method

Since this method of making the two overlays appear and disappear doesn't work, there is an alternative that works once and then stops working after the first try. And these two behaviors are NOT tied to the scene itself, rather they are tied to two different overlays.

For 2D Overlay1, when Escape is pressed, make 2D Overlay1 invisible and 2D Overlay2 visible.

For 2D Overlay2, when Escape is pressed, make 2D Overlay2 invisible and 2D Overlay1 visible.

Note: Just make sure that one of them starts off invisible in the beginning but the other is still visible.

This method works because the actions work when Escape is pressed ONLY when one of each overlay is visible. If an overlay is not visible, Escape doesn't work. So this conveniently allows you to make one overlay visible and the other invisible and vice versa. It's a simpler and different way of accomplishing what I was trying to do earlier.

But here's the problem.

After pressing Escape two times, it's stops working. So basically, press Escape, 2D Overlay1 disappears (if that's the only overlay you had visible in the beginning) and 2D Overlay2 appears. Press Escape again, 2D Overlay2 disappears and 2D Overlay1 appears. Now, when you press Escape a third time, nothing changes. Nothing that was previously visible becomes invisible and nothing that was previously invisible becomes visible. It stops working. Why??? I don't know!!!

Why does CopperCube make it so difficult to toggle the visibility of two different overlays? I don't know what to do anymore! Please help, thanks!

person icon
guest_haydenstra
Guest
Quote
2025-11-20 20:17:07

Anyone got a fix for this? I just ran into this issue today.

person icon
SamOne
Guest
Quote
2025-11-21 03:54:18

just change from keyPressed Down to KeyReleased or LeftUp, so that it will trigger it when you release the key and it will be trigerred only once and not continuously.

person icon
shadynl
Registered User
Quote
2025-11-22 20:20:06

You should change the variables like this:

When key is pressed- Do something later 10 milliseconds, and then change the attributes.

person icon
wing
Guest
Quote
2025-11-24 09:32:02

I see two possible causes.
The first one might be related to the fact that the When a key is pressed do something event is attached to a node that becomes hidden.
Since the behavior itself is added to that node, when the node is hidden it may stop executing its code because it is removed from the processing flow.
In any case, the general approach used in the original post is incorrect.
The variable Box is used as a state indicator, but what actually need is a system that checks the previous key state.
In other words, Box (or *MainState*) should represent the toggle state (0 or 1),
and you also need variables to detect whether the key was pressed this frame and the previous frame: LastPress and CurrentPress.
Here is the structure:
1. Under When a key is pressed do something -> Key Pressed Down set CurrentPress = 1
2. Then run your main logic inside Every few seconds do something, for example every frame:
If LastPress < CurrentPress this means the key was just pressed this frame (it wasn’t pressed in the previous frame).
-Increase MainState by 1
-Then check its value. If MainState > 1 set it back to 0
Right after updating MainState, set LastPress = CurrentPress.
3. After this logic, inside When a key is pressed do something -> Key Left Up set CurrentPress = 0
4. Now, in the same Every few seconds do something loop, you can check the value of MainState and perform actions depending on whether it is 0 or 1

embedded external image
🔎︎


person icon
vp
Guest
Quote
2025-11-25 12:49:34

...instead of using "make visible" and "make invisible" twice, on two separate overlays, dependent on which state they are in (hidden/visible) and a generic "esc" which you want to work when either overlay is visible..... make it simpler....

1- use the "when space pressed to toggle visibility" on both overlays.

2- in scenegraph editor, manually set one overlay visible and one invisible.

3- child(drag/drop) both overlays onto a parent which just has "press spacebar to make visible" and "press escape to hide.

to make it work, place all the parent and overlay nodes into a folder (called eg: "overlay controller") and attach all the commands to the folder (not the items/nodes/overlays themselves). Make the commands point to the active node (rather than using "affects current node").

Here's all my project files; if you want to check the "Nekron" game, it has an overlay card-system completely controlled by mouse (you can change it to keyboard), it does exactly what you're trying to do...
https://mega.nz/folder/JCNmAQ7J4...


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |