PLEASE HELP! NEED HELP FIGURING OUT CODE FOR PROJECT. Thanks :0)
dragontales
Posts: 6
in BASIC Stamp
Hi so I'm making a guitar hero like game. Basically three LEDs with 3 buttons. When one comes on press and it you gain score, miss it an you lose score. pretty simple. I have a few errors and things I can't figure out. I can paste a portion of the code that is having the issues and list what I need help with. If i anyone can please help that would be amazing.
1)Even if you sucsesfully press the button it still takes away score. I know why it does but I can't figure out how to stop it from doing so while still turning the light off.
2) When you press the LED you can just hold it down and "cheat" gaining as much score as you want. I have no idea how to fix this.
3) this is not a big issue but it there a way to play a song in the background? I have it all coded and it works but I'm not sure how to do this.
Code: (Don't worry about it being in a procedure. I need to use a lot of these so its just there already.)
Note2:
leveltime = 10000
DO WHILE leveltime > 0
HIGH 2
IF IN11 = 0 THEN
GOSUB winner
ENDIF
leveltime = leveltime - 25
LOOP
LOW 2
GOSUB loser
RETURN
loser:
score = score - 10
DEBUG ? score
RETURN
winner:
score = score + 1
DEBUG ? score
RETURN
1)Even if you sucsesfully press the button it still takes away score. I know why it does but I can't figure out how to stop it from doing so while still turning the light off.
2) When you press the LED you can just hold it down and "cheat" gaining as much score as you want. I have no idea how to fix this.
3) this is not a big issue but it there a way to play a song in the background? I have it all coded and it works but I'm not sure how to do this.
Code: (Don't worry about it being in a procedure. I need to use a lot of these so its just there already.)
Note2:
leveltime = 10000
DO WHILE leveltime > 0
HIGH 2
IF IN11 = 0 THEN
GOSUB winner
ENDIF
leveltime = leveltime - 25
LOOP
LOW 2
GOSUB loser
RETURN
loser:
score = score - 10
DEBUG ? score
RETURN
winner:
score = score + 1
DEBUG ? score
RETURN
Comments
Just take off that extra space inside the brackets
What exactly would this do?
Two things:
1) It keeps your spaces in place (which are very important for reading your Spin )
2) It uses a monospace font, which makes it much easier to read code (not as important as the first)
I have no idea if that worked but okay. Can you help me with my other problems at all?
Hello?
Without seeing the entire program and a diagram of how it is all connected it's really hard to help anyone.
For music I use a serial MP3 player they work great.
Your main problem is that you constantly call the winner subroutine as long as the button is pushed, and then call the loser subroutine whether or not the button was pushed, when I think you only want to call winner or loser once after it has been determined if the button was pushed or not.
Instead, you should declare two variables, one to indicate if the right button was pushed, and the other to indicate if a wrong button was pushed. Set them both to zero before your DO WHILE LOOP, and inside the DO WHILE LOOP, constantly check if the right button was pressed, in which case you should set the "win" variable to 1, or if the wrong button was pressed, in which case you should set the "wrong" variable to 1. Then, after your DO WHILE LOOP, you should call winner or loser depending on which of win and wrong are set. Note that they could both be set if the right and a wrong button were pushed, or just one could be set if only the right or the wrong button was pushed, or neither if no buttons were pushed.
Also, you should probably move your HIGH 2 and LOW 2 to before and after your DO WHILE LOOP, since you don't need to be constantly turning it on and off hundreds of times a second.
Whoops! I walked into the wrong classroom :P I thought this was the Propeller forum.
Thanks for the help. I kind of understand what you mean but I don't at the same time. I haven't been using this program for long. Would you be able to show and example? It would be greatly appreciated.
And yes that it the main problem. It run winner if I press the button but either way it runs loser. Also do you know how to fix my second issue? If you can't thats all good. Any help is very much appreciated.
Thanks
If you want the loop to exit as soon as the right or wrong or either button is pushed, then change the DO WHILE line to also have something like "AND (NOT wrong) AND (NOT win)".
I have it set up so that if you push the right button and a wrong button loser gets called twice, but if you only push the wrong button, loser gets called only once. I wasn't sure what behavior you wanted in this case, but you can change it easily
You're just 20,000 helpful posts away from being the next Mike Green.