issue with key doing two different things (conditionally)

For questions about using Classic.

Post » Sat Jan 31, 2009 5:18 am

so i have a button that i want to use as 'catch ball' and 'pass ball'. you can't pass a ball unless you have a ball. you can only catch a ball if you don't already have one.

but about half the time when i catch a ball, it will automatically pass it at the same time. i do have it set to 'when control pressed' and not 'when control is down' (and FYI, they are different controls but listed as the same key). i could understand if it always passed (and re-ordering events would probably be enough to fix)... but oddly enough it seems to choose what it will do randomly (seems to be equal chance of doing either). any tips on how i could easily fix this? i can think of ways but they're more cumbersome than i'd like -- and hey, i usually learn new shortcuts when asking questions :P.

edit: weird.. it's literally like alternating between the two. even if i change layouts and go back to the gameplay layout. it's not random... it's just alternating between the two.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

Post » Sat Jan 31, 2009 6:57 am

Well, without looking at the .cap I can only guess what's going wrong... but I would assume that it's because of the order of events. When you have two "On control pressed" triggers in one tick, they both will trigger. So if you have:

[code:2s95oxjz]
+On control "Ball" pressed
->Catch ball

+On control "Ball" pressed
->Pass ball
[/code:2s95oxjz]

then both action 1 and 2 will trigger. You might have to structure it like so:

[code:2s95oxjz]
+On control "Ball" pressed
+value('hasBall') is equal to "true"
->Pass ball
+Else
->Catch ball
[/code:2s95oxjz]

That way you're only doing one control check, but depending on the sub-events there could be two different outcomes.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sat Jan 31, 2009 7:40 am

well it's more like this

[code:3la0rcfr]
+On control "p1_catch" pressed
->Catch ball

+On control "p1_pass" pressed
->Pass ball
[/code:3la0rcfr]

both controls are mapped to the same key though.* but half the time, it will catch and immediately pass the ball, but the other half of the time, it will only catch the ball. if it auto-passed it last time, it will just catch it -- and if it only caught it last time, it will auto-pass it the next. this pattern of alternating back and forth continues even if i go to main menu layout and back to gameplay layout, but i don't use global variables for these, either.

*i chose to use two different controls because, in the future, i plan to implement customizable controls -- default control scheme will have them on the same key/button.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

Post » Sat Jan 31, 2009 7:53 am

+private.variable = 0
+On control "p1_catch" pressed
->Catch ball
->set private.variable to 1
+private.variable caught =1
+On control "p1_pass" pressed
->Pass ball
->set private.variable to 0
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Sat Jan 31, 2009 8:19 am

[quote="newt":2ihx7c1l]+private.variable = 0
+On control "p1_catch" pressed
->Catch ball
->set private.variable to 1
+private.variable caught =1
+On control "p1_pass" pressed
->Pass ball
->set private.variable to 0[/quote:2ihx7c1l]
i'm already doing something similar, but with testing for 'is animation playing' rather than private variables. you'd have to switch the order in your example though, or it'd always fly through both (the order of mine apparently doesn't matter, because either way it still does it half the time).

the odd behavior is that it only auto-passes half the time.

edit: if it makes any difference, i'm using Functions for the actual actions.
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

Post » Sat Jan 31, 2009 10:00 pm

what's the simplest way i could implement a delay after you catch it before you could pass it? hopefully something simpler than creating a variable and have it count down... i just need it to not let you pass it immediately. seems like a 'wait a tick' action would be useful :P
B
2
S
2
G
4
Posts: 254
Reputation: 1,958

Post » Sat Jan 31, 2009 11:25 pm

Well you said your using animation playing... how long's the animation?
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Sat Jan 31, 2009 11:43 pm

[quote="newt":1x0gjzti]Well you said your using animation playing... how long's the animation?[/quote:1x0gjzti]
right now just placeholder 1 frame animations showing whether the ball is behind held or not, but yeah i think your idea will probably work. 8)

thanks
B
2
S
2
G
4
Posts: 254
Reputation: 1,958


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests