How do I make a character screen

Get help using Construct 2

Post » Sat Feb 20, 2016 9:04 pm

Hi. I want to make a character window to pop up when player presses C.

So far so good:
On keyboard C pressed -> create object Character_Window on layer HUD ...

How do I make the window disappear when i click C again though? I tried different ways but cant figure out still. Maybe with instance variables? I thought this is a simple thing to do, so please explain me :)
B
10
S
4
Posts: 34
Reputation: 874

Post » Sat Feb 20, 2016 9:26 pm

Use a variable - CharacterWindowVariable

Code: Select all
On keyboard C pressed       | Create CharacterWindow
CharacterWindowVariable = 0 | Set CharacterWindowVariable = 1-CharacterWindowVariable

On keyboard C pressed       | Destroy CharacterWindow
CharacterWindowVariable = 1 | Set CharacterWindowVariable = 1-CharacterWindowVariable

Mistakes were made.
B
52
S
26
G
108
Posts: 1,605
Reputation: 61,131

Post » Sat Feb 20, 2016 9:53 pm

@oosyrag

Thank you for your help.
Sadly it's not working. I think it is still creating and destroying the window at the same time and therefore nothing happens. If I put a wait - 0.1 seconds before changing the variable - the window apears, but i can't close it....

Any ideas?
B
10
S
4
Posts: 34
Reputation: 874

Post » Sat Feb 20, 2016 9:57 pm

UPDATE: I put wait 0.1 seconds after destroying the object and it finally works :)
B
10
S
4
Posts: 34
Reputation: 874

Post » Sat Feb 20, 2016 10:06 pm

Whoops yes I made another very common beginner mistake. Actually I recommend not using wait - it is the cause of a lot of headaches. Add ELSE to the second event.

I forgot about that. If you use else, you might not need a variable at all.

On C pressed, if CharacterWindow does not exist - Create CharacterWindow
ELSE On C pressed - Destroy CharacterWindow
Mistakes were made.
B
52
S
26
G
108
Posts: 1,605
Reputation: 61,131

Post » Sat Feb 20, 2016 10:40 pm

oosyrag wrote:Whoops yes I made another very common beginner mistake. Actually I recommend not using wait - it is the cause of a lot of headaches. Add ELSE to the second event.

I forgot about that. If you use else, you might not need a variable at all.

On C pressed, if CharacterWindow does not exist - Create CharacterWindow
ELSE On C pressed - Destroy CharacterWindow


Can't add "Else". Probably because I have the condition of pressing C which cannot have "else". Any ideas? :roll:
B
10
S
4
Posts: 34
Reputation: 874

Post » Sat Feb 20, 2016 11:22 pm

Else has to be the top condition in the event

EDIT: Ok so you can't use else after a trigger.

The workaround is to make a sub event after pressing c, check if window open, then the next event after that is else.

Code: Select all
On C Pressed
|
+- Check if Window exists - Make Window
+- ELSE - Destroy Window
Mistakes were made.
B
52
S
26
G
108
Posts: 1,605
Reputation: 61,131

Post » Sun Feb 21, 2016 11:55 am

Yep, it works:

On C pressed
- System compare two values: CharacterWindow.count < 1 --> create CharacterWindow
- Else destroy Character Window

Thanks for your help :)
B
10
S
4
Posts: 34
Reputation: 874


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 25 guests