Move a sprite with any click like a boolean.

Get help using Construct 2

Post » Fri Mar 14, 2014 3:25 pm

Hello excuse my english,

I don't understand, i want to move a sprite Y-125 with "any click" and the second "any click" Y+125 for the sprite back in its place.
Like a boolean, i do this.

code_c2.png


and this

code_c2_2.png



But the 2 lines in the same time don't works.
with the 2 lines the sprite don't move.
The 2 lines vanish?

I go the wrong way ?

Thanks.
Chris.
You do not have the required permissions to view the files attached to this post.
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Fri Mar 14, 2014 4:27 pm

If you set c_haut to 1 then the second code triggers immediately, because then c_haut is 1. You have to structure it another way.
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Fri Mar 14, 2014 5:13 pm

try -
Ashampoo_Snap_2014.03.14_17h07m47s_001.png


but - instead of a global variable why not add an instance variable (boolean) to your sprite ?

you would get :
Ashampoo_Snap_2014.03.14_17h10m46s_002.png
You do not have the required permissions to view the files attached to this post.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Fri Mar 14, 2014 5:30 pm

This will also not work. Because the first condition will trigger the else statement.

He has to use a boolean and reset it with key release.

I have to go now. I will post a solution later, if the problem then still exists.
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Fri Mar 14, 2014 5:52 pm

@Alyra Games
Nope! It's a good solution. The else is bound to the evaluation of the condition it's "elsing", since this evaluation happens before the action, the else will not be triggered.

@RamPackWobble
Using a boolean instead of a global number is not equivalent though it might be a better solution in this case. But we can't say without seeing the big picture.
I would guess that you probably want to use a boolean for the semantic (meaning) of a 0/1 switch, but to me it's more because c2 doesn't provide boolean types for globals than for a good design reason.
(To counter c2's flaw, I usually declare two global constant TRUE = 1 and FALSE = 0 and use that in expressions)
B
66
S
22
G
14
Posts: 1,484
Reputation: 16,511

Post » Fri Mar 14, 2014 7:44 pm

Alyra Games wrote:This will also not work. Because the first condition will trigger the else statement.

He has to use a boolean and reset it with key release.

I have to go now. I will post a solution later, if the problem then still exists.


?

mouse click else test 02.capx

mouse click else test 01.capx


@Yann - good idea about the TRUE/FALSE globals. I agree about using boolean being different to globals just thought I would offer a possible variation...
You do not have the required permissions to view the files attached to this post.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Fri Mar 14, 2014 10:48 pm

Thanks a lot ! i'm going to try :)
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Fri Mar 14, 2014 11:28 pm

it's works !
it was missing "esle"
The 2 work but I chose the capx1 without boolean.

Thanks. ;)
B
12
S
3
Posts: 147
Reputation: 2,026

Post » Sat Mar 15, 2014 1:14 am

Yann wrote:since this evaluation happens before the action, the else will not be triggered


Oh, I didn't know that. You never stop learning. :D
B
10
S
2
Posts: 135
Reputation: 1,090


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 62 guests