Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / newbie here having problems with getting a simple program to rum

Author
Message
I am a beginner and need help
18
Years of Service
User Offline
Joined: 12th Apr 2006
Location: USA
Posted: 15th Jan 2011 10:18
remstart
-------------------------------
beginners guide to game programming with darkbasic
copyright (C)2002 Jonathan S. Harbour and Joshua R. Smith
chapter 5 - looping command 4
-------------------------------
remend

rem This program bounces your name around the screen
rem This program is written with the use of a DO....LOOP loop
rem This program will stop after the 10 time of bouncing

print "Jonathan Leigh Miller:"
input name$

count = 1
do
cls
text rnd(500),rnd(350),name$
sleep 500
count = count + 1
if count > 10 then exit
loop

ok the program prints the name on the screen and it wont bounce around like it is supposed to. This program is from the 'BEGINNERS GUIDE TO DARKBASIC GAME PROGRAMMING, from chapter 5 I've typed in the code exactly the way it appears in the book and even checked it over a few times but still cant get it to make the text bounce around the screen. Any help would be greatly appreciated.
Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 15th Jan 2011 10:59
your problem is in your input code
the format for inputting data is

input "text relating to input",data$

so to fix your code so it works change

input name$
to
input "enter your name",name$

now it will work

Sometimes I like to use words out of contents
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 15th Jan 2011 15:26
The syntax you are using is correct. There is nothing wrong with using the input command the way you have.

When you run your code, you're seeing your name pop up on the screen and just sit there, doing nothing, right? The reason it's not working for you is because you've taken the book you're reading from too literally! I've not seen the book you're reading from, but I can plainly tell that these two lines of code, as it's printed in the book, read like this:

PRINT "Enter your name:"
INPUT name$

It's obvious to me that when you've typed the code into your program, you've changed the text Enter your name to your actual name! You've typed this into your program:

PRINT "Jonathan Leigh Miller"
INPUT name$

When you run this code, the PRINT command makes the program display your name at the top of the screen, which is what you're seeing when you run your program. The problem that you're experiencing comes at the very next line of code - the INPUT command.

This command makes the computer STOP and WAIT for you to type something. If you don't type anything, nothing will happen and whatever text is between the quotes in your PRINT command will just sit at the top of the screen, doing nothing, while the program waits for you to type something!

The original code is supposed to PRINT "Enter your name" so that when you run the program, that text (ENTER YOUR NAME) appears at the top of the screen, instead of JONATHAN LEIGH MILLER. Then the program hits the INPUT command, so it will wait for you to do what it's asked you to do, enter your name!

Change the code back so that the PRINT command reads ENTER YOUR NAME and not your actual name. Then when you run the program, it will ask you to enter your name and then wait for you to do so. When you type your name and hit enter, it will start popping around the screen.

Try it and see if it works - let me know if you have any more problems!
I am a beginner and need help
18
Years of Service
User Offline
Joined: 12th Apr 2006
Location: USA
Posted: 16th Jan 2011 10:39
Ok I've got it fixed now thanks for the advice guys.

Login to post a reply

Server time is: 2024-11-23 03:40:39
Your offset time is: 2024-11-23 03:40:39