Help using Global Variables

For questions about using Classic.

Post » Mon Mar 08, 2010 9:34 am

Oye again, just another quick problem I am having a hard time resolving:

I need to have the controls set up so when you press '1' it disables 'Ghostcrown' and sets everything it disabled back to enabled as well as enabling 'Ghostcrown' at the end so you can repeat. The problem I come to is that when '1' is pressed, it both activates and de-activates everything at once.



B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Mon Mar 08, 2010 4:20 pm

[quote:1eigazkr]The problem I come to is that when '1' is pressed, it both activates and de-activates everything at once.[/quote:1eigazkr]

Both of your "On key 1 pressed" triggers are triggering in the same tick.

Example:

[code:1eigazkr]
+ On key X pressed
+ "Foo" is equal to 1
-> Set "Foo" to 2

+ On key X pressed
+ "Foo" is equal to 2
-> Set "Foo" to 1
[/code:1eigazkr]

You might think this would toggle the value back and forth between 1 and 2 with each keypress. But no. Practically speaking, Foo will never equal 2. If you press X then both of the "X pressed" triggers will run. In the first, you set Foo to 2. Since it's 2 now, then when you reach the second trigger Construct says "Oh, the X key has been pressed... and Foo is equal to 2 so let's run the event. And it sets it right back to 1.

Looking at the post before that one it appears that you have just made a simple logic error and if you look at it again I'm sure you'll see it pretty easily ;)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Mar 08, 2010 8:50 pm

Thank you, I have fixed the issue regarding the crown showing up while the inventory is visible.

I am still unsure as to how to fix the issue of pressing the same key to activate the ghostcrown and take it off.
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Tue Mar 09, 2010 5:07 am

I had something like that happen before. I'd use:

[code:23wuk6gp]
+ On key X pressed
++ "Foo" is equal to 1
-> Set "Foo" to 2

++Else
-> Set "Foo" to 1
[/code:23wuk6gp]
(++ means subevent.)
Here's how it works: When X is pressed, it checks the first subevent. If the first subevet it true, it will trigger the actions in the subevent. It will see the "Else" in the next event and will not even do anything else with that subevent. If the first subevent is NOT true, it will see the "Else" and will check if the second subevent is true. The second subevent needs no other conditions because it has two IMPLIED conditions: "On X key is pressed" and "'Foo' is NOT 1" ("Foo" can only equal 1 or 2 so this is the same as "'Foo' is 2"). This will work together as a toggle between the two values of "Foo" when X is pressed.
B
2
S
2
G
2
Posts: 372
Reputation: 1,794

Post » Wed Mar 10, 2010 2:08 am

[quote="Mr Wolf":14j1r9b7]I had something like that happen before. I'd use:

[code:14j1r9b7]
+ On key X pressed
++ "Foo" is equal to 1
-> Set "Foo" to 2

++Else
-> Set "Foo" to 1
[/code:14j1r9b7]
(++ means subevent.)
Here's how it works: When X is pressed, it checks the first subevent. If the first subevet it true, it will trigger the actions in the subevent. It will see the "Else" in the next event and will not even do anything else with that subevent. If the first subevent is NOT true, it will see the "Else" and will check if the second subevent is true. The second subevent needs no other conditions because it has two IMPLIED conditions: "On X key is pressed" and "'Foo' is NOT 1" ("Foo" can only equal 1 or 2 so this is the same as "'Foo' is 2"). This will work together as a toggle between the two values of "Foo" when X is pressed.[/quote:14j1r9b7]

Thank you very much! Everyone's been helpful here.
B
8
S
1
G
2
Posts: 79
Reputation: 1,108

Post » Wed Mar 10, 2010 7:06 am

Alternatively:

+ Key X is pressed
> Foo = 1 - Foo

A simple trick - if Foo is 0, you get 1, if Foo is 1, you get 0. It switches back and forth. ;)

Then you can make your inventory event trigger once:

+ Foo = 1
+ Trigger Once While True
> Stuff
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Previous

Return to Help & Support using Construct Classic

Who is online

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