Shop OBEX P1 Docs P2 Docs Learn Events
PLEASE HELP! NEED HELP FIGURING OUT CODE FOR PROJECT. Thanks :0) — Parallax Forums

PLEASE HELP! NEED HELP FIGURING OUT CODE FOR PROJECT. Thanks :0)

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


Comments

  • Any help is appreciated! thank you :)))
  • Please surround your code with code brackets, like so:
    [code]PUB Main
        myCool = code[/code ]
    

    Just take off that extra space inside the brackets
  • DavidZemon wrote: »
    Please surround your code with code brackets, like so:
    [code]PUB Main
        myCool = code[/code ]
    

    Just take off that extra space inside the brackets

    What exactly would this do?

  • DavidZemon wrote: »
    Please surround your code with code brackets, like so:
    [code]PUB Main
        myCool = code[/code ]
    

    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)

  • dragontalesdragontales Posts: 6
    edited 2016-01-21 22:01
    PUB Main
    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
    myCool = code
    

    I have no idea if that worked but okay. Can you help me with my other problems at all?
  • DavidZemon wrote: »
    DavidZemon wrote: »
    Please surround your code with code brackets, like so:
    [code]PUB Main
        myCool = code[/code ]
    

    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)

    Hello?

  • I made something similar. I started out with one button but never finished the three button version. Here's a link - http://forums.parallax.com/discussion/150319/basic-stamp-mini-game

    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.
  • The PUB Main stuff only applies to Spin on the Propeller, but you're using the Basic Stamp, so you don't need it (and it won't work). David Zemon was just trying to tell you to use [ code ] [ /code ] tags (without the spaces) and needed somethiing to put within the code tags.


    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.
  • The PUB Main stuff only applies to Spin on the Propeller

    Whoops! I walked into the wrong classroom :P I thought this was the Propeller forum.
  • dragontalesdragontales Posts: 6
    edited 2016-01-21 23:33
    The PUB Main stuff only applies to Spin on the Propeller, but you're using the Basic Stamp, so you don't need it (and it won't work). David Zemon was just trying to tell you to use [ code ] [ /code ] tags (without the spaces) and needed somethiing to put within the code tags.


    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.

    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
  • ElectrodudeElectrodude Posts: 1,650
    edited 2016-01-22 04:27
    This should do the trick, but I haven't tested it. I assumed that your had two other buttons on IN10 and IN12. This subroutine only handles one note - you'll need to either make copies for the other note or modify this one to work with any of them.

    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
    win VAR bit
    wrong VAR bit
    
    '-----------------------------------------
    
    Note2:
      leveltime = 10000
      win = 0
      wrong = 0
    
      HIGH 2
      DO WHILE leveltime > 0
        IF IN11 = 0 THEN
          win = 1
        ENDIF
        IF IN10 = 0 OR IN12 = 0 THEN
          wrong = 1
        END
        leveltime = leveltime - 25
      LOOP
      LOW 2
    
      IF win THEN
        GOSUB winner
      ELSE
        GOSUB loser
      END
    
      IF wrong THEN ' if an incorrect button was pushed
        GOSUB loser
      END
    
    RETURN
    
    '-----------------------------------------
    
    loser:
      score = score - 10
      DEBUG ? score
    RETURN
    
    winner:
      score = score + 1
      DEBUG ? score
    RETURN
    
  • ercoerco Posts: 20,256
    Electrodude, you're a very good man for diving in and helping here. Bravo I say!

    You're just 20,000 helpful posts away from being the next Mike Green. :)
Sign In or Register to comment.