[Make it easier] Switching events

For questions about using Classic.

Post » Mon Jan 04, 2010 8:58 pm



The reason this one doesn't work is because events are executed top to bottom. The logic is more like this:

[code:2ljvzfef]If group on is activated
If space was pressed
Disable group on and enable group off
If group off is activated - (which the previous line just activated)
If space was pressed
Disable group off and enable group on[/code:2ljvzfef]

Because group 'off' is enabled in event 1, in the same cycle the second event runs.

Another solution might be to put the 'space is pressed' code outside the groups and use 'toggle group'

eg:

[code:2ljvzfef]
If group on is activated
If space was pressed
do stuff
If group off is activated
If space was pressed
do stuff
If space was pressed
toggle group "on"
toggle group "off"
[/code:2ljvzfef]
B
4
S
2
G
5
Posts: 641
Reputation: 3,011

Post » Mon Jan 04, 2010 9:04 pm

funny though, it works after the first round.

Perhaps disabling/enabling groups only goes effective on the next frame and this is a bug? (on default-disabled groups not really being disabled?)
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Jan 04, 2010 10:42 pm

[quote="Mary Jane":bd9iwy9i][/quote:bd9iwy9i]

Agh, sorry, I misinterpreted what you were trying to do, and messed up the example regardless. Here it is fixed:

event 1 conditions:
- On space pressed
event 1 actions:
- set 'spacepressed' to 1

event 2 conditions:
- If variable 'spacepressed' is 1
- If variable 'on' is 1
event 2 actions:
- Sprite: set x position to sprite.x+64
- set 'spacepressed' to 0
- set 'on' to 0

event 3 conditions:
- If variable 'spacepressed' is 1
- If variable 'on' is 0
event 3 actions:
- Sprite: set x position to sprite.x-64
- set 'spacepressed' to 0
- set 'on' to 1

event 4 conditions:
- Always
event 4 actions:
- set 'spacepressed' to 0

If that doesn't work I'll make an example.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Tue Jan 05, 2010 3:15 am

wow these are all really really complicated for something really simple....
[code:1s1c60b8]

-> on space pressed: switchVar = switchVar * -1; //Starting Value of switch var = -1
-->If SwitchVar == 1: sprite.x += 64 //adds 64 to the current X value
-->if Switchvar == -1 : sprite.x -= 64 // subtracts 64 from the current X value[/code:1s1c60b8]
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Tue Jan 05, 2010 3:49 am

yeah its a flow control issue. this worked too. If it was more than one state, It would be difficult.

+ MouseKeyboard: On any key pressed
+ System: Is global variable 'lulz' Equal to 0
-> System: Set global variable 'lulz' to 1
-> Sprite: Set X to Sprite.X + 64
+ System: Else
-> System: Set global variable 'lulz' to 0
-> Sprite: Set X to Sprite.X - 64
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Jan 05, 2010 6:47 am

If I add one to zero I get 1, that number is odd. If I add one to that, and get two, that number is even.
If I add one to that and get three, I have a pattern, because that number is odd.
[url:3h2zuot9]http://dl.dropbox.com/u/666516/easyspace.cap[/url:3h2zuot9]

+ MouseKeyboard: On key Space pressed
-> Sprite: Add 1 to 'num'
-+ System: Sprite.Value('num') modulo 2 Different to 0
---> Sprite: Set Y to Sprite.Y-64
-+ System: Else
---> Sprite: Set Y to Sprite.Y+64
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Jan 05, 2010 6:06 pm

Thank you very much!!!
Your methods using variables are really working. I especially liked the ansmesnobody's solution:



This is similar to my third method in the first post.

I think the David's method is the best, because it consists only of 3 events and doesn't use any variables.



It's really simple and works perfectly.
Thanks!
B
3
S
2
G
3
Posts: 146
Reputation: 1,567

Post » Tue Jan 05, 2010 7:05 pm

You shouldnt need the trigger once for those sub events. also you could put them in with the comparison. the On key pressed acts as a trigger once for all the sub events.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Tue Jan 05, 2010 7:41 pm

[quote="Aeal5566":41ondb1m]You shouldnt need the trigger once for those sub events. also you could put them in with the comparison. the On key pressed acts as a trigger once for all the sub events.[/quote:41ondb1m]

Thanks! :D
B
3
S
2
G
3
Posts: 146
Reputation: 1,567

Post » Tue Jan 05, 2010 8:57 pm

Duh! never thought of toggling groups from outside XD
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

PreviousNext

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests