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

  • Thread starter Thread starter CharlieO1212
  • Start date Start date
  • Tags Tags
    Input Programming
Click For Summary

Discussion Overview

The discussion revolves around programming in Chipmunk Basic, specifically focusing on handling user input to control sprite movement using keyboard keys. Participants explore how to implement key presses for movement without prompts and address issues related to the program's functionality and behavior.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant seeks help to program sprite movement in Chipmunk Basic using specific keys ("w" for up, "s" for down) without prompts.
  • Another participant suggests a basic loop structure using the inkey$ function to detect key presses and respond accordingly.
  • A participant shares their code and confirms that it successfully detects key presses but seeks further assistance with more complex movement logic.
  • One participant describes issues with an endless loop and incorrect cursor movement in their code, requesting help to resolve it.
  • Another participant provides a revised code snippet to address the cursor movement and printing issues, suggesting the use of spaces to overwrite previous output.
  • One participant reports a problem with extra characters appearing when pressing "w" and seeks clarification on how to fix it.
  • Participants discuss potential solutions for boundary conditions to prevent the sprite from moving off-screen.
  • A participant expresses interest in creating a game using Chipmunk Basic and asks for ideas, mentioning a previous attempt at a snake game that did not work.

Areas of Agreement / Disagreement

Participants generally agree on the programming approach and share solutions, but there are unresolved issues regarding specific code behavior and the implementation of game ideas. No consensus exists on the best method for handling certain programming challenges.

Contextual Notes

Some code snippets may not function as intended due to potential typographical errors or limitations in Chipmunk Basic's handling of input and output. Participants also note that formatting issues may affect how code is displayed in the forum.

Who May Find This Useful

Individuals interested in programming with Chipmunk Basic, particularly those looking to implement user input for sprite movement or develop simple games.

CharlieO1212
Messages
10
Reaction score
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
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:
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
 
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.
 
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:
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?
 
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:
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
 

Similar threads

Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
4
Views
5K
Replies
10
Views
5K
  • · Replies 41 ·
2
Replies
41
Views
5K
  • · Replies 11 ·
Replies
11
Views
1K
Replies
1
Views
3K