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

In summary, you are trying to program something that will move a sprite up and down when a key is pressed.
  • #1
CharlieO1212
10
0
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 don't work) and so i wanted help programming something that when a key is pressed it acts like an arrow key. I don't 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!
 
Technology news on Phys.org
  • #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:
  • #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
 
  • #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.
 
  • #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:
  • #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?
 
  • #7
CharlieO1212 said:
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 "-".

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.

CharlieO1212 said:
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?

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:
  • #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
 

1. How do I write a program in Chipmunk Basic?

To write a program in Chipmunk Basic, you can use a text editor such as Notepad or TextEdit to type in the code. Make sure to follow the syntax and rules of the language, and save the file with a .bas extension.

2. What is an input in Chipmunk Basic?

An input in Chipmunk Basic is a statement that allows the user to enter data or information into the program while it is running. This can be used to make the program more interactive and dynamic.

3. How can I have an input that doesn't show in Chipmunk Basic?

To have an input that doesn't show in Chipmunk Basic, you can use the INPUTHIDDEN statement. This will allow the user to input data without it being displayed on the screen. You can also use the INPUTBOX statement to prompt the user for input in a dialog box.

4. Can I use variables with inputs in Chipmunk Basic?

Yes, you can use variables with inputs in Chipmunk Basic. You can store the input from the user in a variable and use it in your program for calculations or other purposes.

5. How do I handle errors with inputs in Chipmunk Basic?

To handle errors with inputs in Chipmunk Basic, you can use the ON ERROR statement. This will allow you to catch any errors that may occur while the user is entering data and handle them accordingly in your program.

Similar threads

Replies
4
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
9
Views
865
  • Programming and Computer Science
Replies
2
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
10
Views
3K
  • Programming and Computer Science
2
Replies
41
Views
3K
  • Programming and Computer Science
Replies
11
Views
780
  • Programming and Computer Science
Replies
7
Views
1K
Back
Top