Page 1 of 1

Help with PRINT command...

Posted: Sun Jul 15, 2007 1:47 pm
by misticalbobo
Okay I'm new to programming and I'm making a text RPG Battler to practice coding. So I wanted to know if theres a way to make the text go down a line without doing this

PRINT "1. Attack"
PRINT "2. Defend"
PRINT "3. Magic"
PRINT "4. Escape"

Because that's the only way I know, lol. Just wondering if there's a more convenient way.

Posted: Mon Jul 16, 2007 5:01 am
by Ralph
Unless you plan to print these four lines more than once, your way is the best way.

If you plan on printing those lines many times, this way is better:

Code: Select all

DIM P(4) AS STRING
P(1) = "1. Attack" 
P(2) = "2. Defend" 
P(3) = "3. Magic" 
P(4) = "4. Escape" 

Then, each time you need to print the above, you use:

Code: Select all

FOR I = 1 TO 4
  PRINT P(I)
NEXT I

Posted: Mon Jul 16, 2007 10:29 am
by Nodtveidt
If you're talking about a way to manually position text, what you want is the LOCATE keyword.

Posted: Wed Jul 18, 2007 1:00 pm
by Patz QuickBASIC Creations
I don't know why you would want to, but you could print a carriage return:

Code: Select all

PRINT "1. Attack" + CHR$(13) + "2. Defend" + CHR$(13) + "3. Magic" + CHR$(13) + "4. Escape" 

Posted: Wed Jul 18, 2007 2:34 pm
by Erik
If you're looking for something similar to the C/C++ "\n" then see the post above me.

If you're going to be writing them out a lot, you could always create a sub called "DisplayBattleText" (or whatever) and store the text in there. Then just use a "CALL DisplayBattleText" in your program when you wanted it.

Locate command works as follows:

Code: Select all

LOCATE 5, 6 'that's y-pos, x-pos
PRINT "Where you stated in the previous command"

Posted: Wed Jul 18, 2007 3:39 pm
by Nodtveidt
DON'T use CALL at all, it's 100% unnecessary. It's like using LET. :D

Posted: Wed Jul 18, 2007 4:53 pm
by Patz QuickBASIC Creations
List of commands to avoid:

DEF FN (use FUNCTION instead)
WHILE (use DO WHILE instead)
LET (omit)
CALL (omit)

and more than likely many others...

Posted: Wed Jul 18, 2007 11:17 pm
by Zoasterboy
If you want to save lines, just use ":" like this

Code: Select all


PRINT "Menu": PRINT "1. Item One": PRINT "2. Item Two"

The ":" represents a new line.