Trouble with buttons and variables

Get help using Construct 2

Post » Tue Nov 08, 2016 2:44 pm

Hello guys, im facing an annoying problem:

I have a button, and when i click it, it sets a variable to change the behavior of the button according to what I want.
Well, the problem is that when I click it, it changes the variable i want but also the next one and so on.
I found a fix by adding a wait action but it doesnt work always.
Is there a way to fix that?

https://drive.google.com/open?id=0B29NMnCApa87MVBNYVlXNENUOGM
B
8
S
2
Posts: 23
Reputation: 555

Post » Tue Nov 08, 2016 2:49 pm

use subevents and an Else condition

>Opcao1 on clicked and Menu=3
>>Modem = 1 ; set modem to 2
>>Else Modem = 2 ; set LEDS to 1

or reverse the order of the events, but the else is cleaner IMO
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Nov 08, 2016 3:10 pm

I forgot to say, its not about taking a decision, its a sequence.
I have 4 buttons that change the text and the next step
I created variables and what happen with the buttons according to a variable
Eg. variable potato = 1 the button 1 "potato" > person clicks it, gets a pic of a potato, set the variable "fish" to 1
variable fish = 1 so button 1 now is named fishes and show a pic of fishes instead of the potato when clicked

Does it make sense?
B
8
S
2
Posts: 23
Reputation: 555

Post » Tue Nov 08, 2016 3:27 pm

We'd need to see more of the code. @Aphrodite 's advise is correct. Have a single 'On clicked', and break down the logic inside sub-events.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Tue Nov 08, 2016 5:42 pm

This is an example of what I need to do. I have to use variables because its a loooongggg "script" that will need to access the info on the variables

.capx attached
B
8
S
2
Posts: 23
Reputation: 555

Post » Tue Nov 08, 2016 10:08 pm

http://www.blackhornettechnologies.com/Construct2Stuff/button_and_variable_issues_BHT.capx

This is a sample. I've made a second Event Sheet.

If you have a ton of these types of scenarios, you'd be better off with some kind of data based mechanism. Either a file, or an Array, or a Dictionary. There should be no need to have every single case as events.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352


Return to How do I....?

Who is online

Users browsing this forum: biasaur, Unconnected and 9 guests