Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Programming in Chipmunk Basic and having an input that doesnt show-see details

  1. Apr 23, 2012 #1
    Ok so this is my altered and rephrased question. I need help programming something that uses an input. Now it is not as simple as it sounds because I want the user of the program to be able to run the program and have several things happen. When he/she runs the program I want him/her to press "w" and have the sprite move up. I want him/her to press "s" and have the sprite move down. In CB (Chipmunk Basic) There are no assigned values to the arrow keys (AKA they dont work) and so i wanted help programming something that when a key is pressed it acts like an arrow key. I dont want the program to come up with something say "please enter the desired key" or something like that. I want the user to be able to run the program and press the key to move up, down, left, right etc.

    If you need more clarification please let me know. Thanks in advance!!!
     
  2. jcsd
  3. Apr 23, 2012 #2
    Try this

    while
    s$=inkey$
    if s$="s" then <<<do something>>>
    if s$="w" then <<<do something>>>
    wend

    and see if you can get that to work for you.

    Begin with <<<do something>>> being REALLY simple, something simple enough that you aren't going to have even more errors to try to figure out, perhaps as simple as
    print "YES! we got an s without need a prompt or a carriage return key"

    If you have errors on line numbers then you need to tell me the line number because I can't see any of this and am just guessing based on 35 year old memory of BASIC and reading the Chipmunk Basic reference manual at
    http://www.nicholson.com/rhn/basic/basic.man.html
     
    Last edited: Apr 23, 2012
  4. Apr 24, 2012 #3
    This is exactly what I typed:
    10 while
    15 let s$=inkey$
    20 if s$ = "s" then print "hello"
    30 if s$ = "w" then print "hi"
    40 wend
    50 end

    When I run the program an i press "s" and "w" it prints both hello and hi so thank you. I will try and make the <<<do something>>> be more complicated and I will let you know
     
  5. Apr 25, 2012 #4
    I have a stupid question. I am using the the help you gave me and it is working but I am having trouble with something else. I am trying to program something that looks like this:

    10 let x = 40
    30 let y = 10
    50 gotoxy x,y
    60 print "<-"
    65 while
    70 let s$ = inkey$
    80 if s$ = "w" then gotoxy x+1,y
    85 print "<-"
    90 if s$ = "s" then gotoxy x-1,y
    95 print "<-"
    100 wend
    110 end

    I am messing up in lines 80,85,90,95 because i am not very good with CB. in the beginning of my program it prints the "<-" but when it gets to line 80 it is stuck in an endless loop. I tried to put the prints in lines 85,90 at the end of line 80 and 90 but it game me a too much information sign. I want the program to move up in 1 x coordinate and no y if either "w" or "s" is pressed. I am having trouble getting the program to move and print my "<-" so i was wondering if you could help me.
     
  6. Apr 25, 2012 #5
    Try this

    10 let x = 40
    30 let y = 10
    50 gotoxy x,y
    60 print "<-"
    65 while
    70 let s$ = inkey$
    80 if s$ = "w" then gotoxy x,y:print" ":let x=x-1:gotoxy x,y:print "<-"
    90 if s$ = "s" then gotoxy x,y:print" ":let x=x+1:gotoxy x,y:print "<-"
    100 wend
    110 end

    80 and 90 are
    moving the text cursor back where it was before you printed the previous <-.
    erasing your old <- by printing two spaces
    changing x to the new coordinate
    printing your new <-

    Let me know if that works.
    Then you will need to add something to not have x go off either edge of the screen.
     
    Last edited: Apr 25, 2012
  7. Apr 26, 2012 #6
    It does work but when i press "w" it keeps adding a "-" to my figure. When i press "s" it does not have this problem so i was wondering how to change it so when i press "w" it moves over and does not print extra lines "-". Also if i assigned a variable to the "<-" and said if "<-" is =80,25 then turn around or something like that in code that should work right?
     
  8. Apr 26, 2012 #7
    Check to see if there are any small differences between the "s" and "w" lines. I tried to make both those the same so that each would print two spaces over the top of the old "<-" to cover that up. Maybe you have a small typo. Or maybe there are subtle things that I can't guess.

    I'm not actually running any of this, I'm doing all this in my head and that makes it very easy for a mistake to slip past me.

    I was thinking perhaps something like

    80 if s$ = "w" then if x>0 then gotoxy x,y:print " ":let x=x-1:gotoxy x,y:print "<-"
    90 if s$ = "s" then if x<25 then gotoxy x,y:print " ":let x=x+1:gotoxy x,y:print "<-"

    or you might be able to use

    80 if s$ = "w" and x>0 then gotoxy x,y:print " ":let x=x-1:gotoxy x,y:print "<-"
    90 if s$ = "s" and x<25 then gotoxy x,y:print " ":let x=x+1:gotoxy x,y:print "<-"

    but you then need to start learning how AND and OR work.

    That would only move up as long as you were not on the top line already and only move down as long as you were not on the bottom line already. But there are other ways to accomplish the same thing and anything that doesn't let x,y exceed the boundaries of the screen will be fine.

    It sounds like you are making progress. I hope it works out for you.

    Note: It looks like the posting process is eating my double spaces and replacing those with a single space. Watch out. This posting software does a variety of little things like that. It is possible to put code inside a box where it isn't supposed to mess with the characters, but I've never taken the time to figure out how to do that, or to learn how to use reverse slant italic bold gothic font supersubscripts either. ASCII text used to be good enough.
     
    Last edited: Apr 26, 2012
  9. Apr 27, 2012 #8
    It worked and all but i have a a question. i want to make a game in chipmunk basic and I was wondering if you had any ideas. I want it to use the arrow keys (w,a,s,d) as well. I tried making a game of snake but it didnt work because CB messed up. I was wondering if you had any ideas.

    Thanks
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Programming in Chipmunk Basic and having an input that doesnt show-see details
Loading...