Text and local variable.

Discussion and feedback on Construct 2

Post » Wed Apr 05, 2017 9:19 pm

Hello, please can anyone tell me why "hola" is not printed when I press the cursor down ?.

The variable "var" is local and only retains its value in the same tick if there is no "wait" action, I do not know why the text is not printed when I press the cursor down.


Image
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Apr 06, 2017 7:33 pm

Hi, any ideas on this?
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Apr 06, 2017 7:53 pm

Hi there. Double-click on the local variable to edit and make sure Static is checkmarked. It will then work.
This will force the variable to stay at the value it was changed to, otherwise it resets back to the initial value.
B
66
S
37
G
111
Posts: 117
Reputation: 60,978

Post » Thu Apr 06, 2017 8:04 pm

Lancifer wrote:Hi there. Double-click on the local variable to edit and make sure Static is checkmarked. It will then work.
This will force the variable to stay at the value it was changed to, otherwise it resets back to the initial value.


Thanks I know that solution, but when I hit the cursor down the variable "var" takes the value 1, then the text should be written, the question is why is not the text written ?.
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Apr 06, 2017 8:15 pm

I don't understand.
Your screenshot shows that you don't have Static checkmarked. Otherwise, it would say "Local static number var = 0".
That is why it's not working.

Image
B
66
S
37
G
111
Posts: 117
Reputation: 60,978

Post » Thu Apr 06, 2017 8:44 pm

Change on key pressed' to 'key is down' ... add 'once while true' to the same event.

Why ?

'on key down' is a trigger. It fires, and then the rest of the events is executed.

So, after firing that trigger, 'it' looks up if it can execute its actions. So, it goes up, meets the Group, is the group active, then the trigger is allowed to run its actions.

After that, 'it' starts with executing top-down. First the group (is it active or not), then resets the local var to zero, then checks if the local is 1.

'key is down' is not a trigger, it stays at its place in the top-down run list.

(making the var static is not a solution if you want to var to reset)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Apr 06, 2017 8:49 pm

Lancifer wrote:I don't understand.
Your screenshot shows that you don't have Static checkmarked. Otherwise, it would say "Local static number var = 0".
That is why it's not working.

Image


But when I hit the cursor down, "var" takes the value 1.

Therefore in the following condition:

System var = 1 Set text "hello"

That condition should be true, after that, the tick ends and "var" is reset to 0.

I know that if the variable is static it is solved, but I want to understand why the text is not written when press down cursor.
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Apr 06, 2017 8:55 pm

Ahh, thanks @99Instances2Go. I'll definitely remember that.
Unfortunately, it doesn't show that in the debugger if it's not static.
B
66
S
37
G
111
Posts: 117
Reputation: 60,978

Post » Thu Apr 06, 2017 9:00 pm

99Instances2Go wrote:Change on key pressed' to 'key is down' ... add 'once while true' to the same event.

Why ?

'on key down' is a trigger. It fires, and then the rest of the events is executed.

So, after firing that trigger, 'it' looks up if it can execute its actions. So, it goes up, meets the Group, is the group active, then the trigger is allowed to run its actions.

After that, 'it' starts with executing top-down. First the group (is it active or not), then resets the local var to zero, then checks if the local is 1.

'key is down' is not a trigger, it stays at its place in the top-down run list.

(making the var static is not a solution if you want to var to reset)


A bit complicated for me the trigger operation, in addition I translate your message to my language.
Thank you, I think something I understood.
B
31
S
13
G
21
Posts: 844
Reputation: 14,693

Post » Thu Apr 06, 2017 9:08 pm

@The Mnk

You have been wrestling with those triggers quite some times.
Can i explain it better ? Tell me what you find complicated ? Or is it my sucky english ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests