if thens and sub routines

OK for my games i rarely use sub programs so where do they get put and also i wanna make it have a menu (i already have the menu made) but i don't want to use if then statements is there another way because i know that i will run into huge problems later on if i use the if-then statements.

Comments

NEW QUESTION

OK for my games i rarely use sub programs so where do they get put and also i wanna make it have a menu (i already have the menu made) but i don't want to use if then statements is there another way because i know that i will run into huge problems later on if i use the if-then statements.

IF...THEN

Hi,

Firstly, sub-routines can be put anywhere, but I would suggest you put them AFTER your main program and before the END statement. This way you don't have to use parameters.

Instead of IF...THEN statements you cane use:

SELECT CASE menuitem
CASE 1
! respond to menu item 1
CASE 2
! respond to menu item 2
CASE 3
! respond to menu item 3 etc.
CASE ELSE
! do nothing because no more valid menu items
END SELECT

menuitem is the number typed by the user as the selected menu.

Big John

ok

but i was making a menu like

1)play game
2)info on game

how would this work?

Menus

Hi,

You need to print the menu on the screen, then you ask the user to type a number, e.g.

CLEAR
PRINT "(1)play game"
PRINT
PRINT "(2)info on game"
PRINT
INPUT PROMPT "Type a number":menuitem

Then you insert the code I gave you earlier containing the select case statement.

Big John

will tis work

will this work for a large game such as 1-5 thousand lines

Menus

Hi,

It will work for any number of lines.

Big John

ok but now this

can a case statement be used inside a case staement

SELECT CASE

Hi,

Yes, select case can be nested inside other select case statements, just like DO....LOOP and IF....THEN.

Big John

Scrolling text

Hi,

One of the easiest ways to scroll text is to BOX KEEP the lines of text then BOX SHOW the image one line higher up the screen. This is very quick even when you are moving a whole screen of text.

You will have to use FONT METRICS to find out the height of the font cell, or you can just experiment. As a guide, 10 point SYSTEM font has a cell height of 16 pixels.

Big John

scrolling

I assume you mean within the output of a program. If you use PRINT statements, they will add lines until you reach the bottom of the window and then additional PRINTS will scroll the text off the top of the window. You can use blank PRINT statements to 'scroll' the text up. You can define a window inside the main window to make this fancy. As I recall you can also create windows with scroll bars but you have to program the scroll bar action--but don't quote me. My manuals are unaccessible at the moment. There may be other controls in the TrueControls library as well--that's where you can create windows with scroll bars and other 'Windows' controls.

rwt

eleaboration

Could you elaborate on this for me. I would like to use this for my intro screen and credits for when someone finishes my game lol. This game is also for my senior project so i would like to make it a little fancy to impress my computer teacher.

scrolling text

Hi Darran,

OK lets assume you want to print say 100 lines of text.
Lets assume you have each line of in a string array.
Lets say you want the text to start scrolling upwards after line 20.
Lets assume you are using COURIER 10 font which has a cell height of 16 pixels.

ASK PIXELS xpix,ypix ! how big is the current window
SET WINDOW 0,xpix-1,ypix-1,0 ! sets pixel co-ordinates

FOR n=1 to 100
PRINT line$(n) ! you could also use PLOT TEXT
IF n>20 then
CALL scrollup
PAUSE 0.2 ! you might need this to slow things down
END IF
NEXT n

SUB scrollup
! Printed area of screen is xpix across and 16*20 down
! BOX KEEP this area
BOX KEEP 0,xpix,320,0 IN image$
! Now show this image one line higher up
BOX SHOW image$ AT 0,(320-16)
! the images overwrites the first 19 lines
! the top line is lost above the top of the window
! the last line is still showing so erase it
BOX CLEAR 0,xpix,320,(320-16)
END SUB

END

It is easy enough to adjust this program for more lines per page and for different font cell heights.

Regards
Big John

Thanks

thank you Big John this should really help make Rothinqua (my games name) a little more interesting. I hope this and actual images of the enemies you fight make my game a good hit in school.

Rothinqua

what happened to final conquest you cheater. you guys realize that you are helping him with his school work right. don't forget that he is lying to you he never had the tbsilver maual because he pirated his copy of tbsilver of of the programming teachers (Mr. Asmondy) original cd when he was installing it