2 player setup?
-
is there a global command for second player controls
how would the controls work for the second player player1/c.a player2/ c.a1 ?? -
@waldron The first controller is index 0 so c0 = controls(0) the second one is index 1 so c1 = controls(1) and so on (up to 3)
-
Just use the controls-function with another index.
Currently you're doing something similar to this:c = controls(0) if c.a then do stuff regarding player one endif
If you want to include a second player it should work like this:
c1 = controls(0) c2 = controls(1) if c1.a then do stuff regarding player one endif if c2.a then do stuff regarding player two endif
This works with up to four players controls(0-3)
*€dit: Okay, @pianofire was a little bit faster :-)
-
@pianofire awesome thanks
-
so while on the subject of controls i played around with (if) and (then)
with the controls so when i pressed certain buttons it would print on the screen what i wanted i thought fantastic so now i can add sounds ect or img but do i have to load full loop code vol. pan ect just to play a sound effect on a button press? -
@waldron The problem arises when using something like:
if j.a then playAudio( blah, blah, blah ) endif
If you are just checking
if j.a
, then this command will trigger every frame the button is held. To stop this, you need to stop the if statement from happening again, once it's been triggered. You could do this with a simple "press" variable:press = false if j.a and !press then playAudio( blah, blah, blah ) press = true // Setting this variable to true means we can't get back into this if until it's false again. endif if !j.a then press = false endif
That method will work just fine, but you might end up needing a separate "press" variable for every button you want to use. I now use this really handy method of storing the previous state of the whole controls structure into one variable, then checking each property when I need it:
// global j = controls(0) oldj = j loop clear() if j.a and !oldj.a then // if a is pressed but was not being pressed on the previous frame // stuff to only trigger once endif oldj = j // before the end of the main loop, update the old controls state variable update() repeat
Just means we don't end up with:
p1aPress = false p1bPress = false p1xPress = false p1yPress = false p2aPress = false
etc etc.
-
@Dave that's great cheers dave iv been reading through the tutorials now i understand them better, iv messed with the audio and got some strange effects bugs but with this method it will work so many thanks man .
now i'm starting to assign scoring for my tricks(+=playercoins = 1) so as of now if i hold a button the score just shoots up but if i apply the same method so it triggers once and even apply (if) velocity such and such il have that working too -
@waldron Fantastic :) You're seeing lots more applications straight away!
-
@Dave said in 2 player setup?:
Just means we don't end up with:
p1aPress = false
p1bPress = false
p1xPress = false
p1yPress = false
p2aPress = falseetc etc.
this would make me want to scoop my own eyes out