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 / MY simple menu

Author
Message
Shay3000
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location:
Posted: 9th Aug 2009 05:46
here's my code I'm not sure if did something wrong if I did please let me know thanks

Rem Project: menutest1
Rem Created: 8/8/2009 5:53:43 PM

Rem ***** Main Source File *****

`// For now just use default video settings //
set display mode 1440,900,32
sync on : sync rate 90
hide mouse

var1=1
var2=2
var3=3
var4=4
var5=5

err=6

print "*********************"
print "seans test menu dbpro"
print "*********************"
print "1 - dumb "
print "2 - bubbles"
print "3 - leave"
print "4 - this"
print "5 - ends menu program."
print "*********************"

input "Enter Number:";var1,var2

`text 50,200,"press 3 on your keyboard"

`// Let's make a menu here simple //

SELECT var=1

CASE 1:

`cls

PRINT "Your a Dumb face!";var=1

wait key

ENDCASE

ENDSELECT

`wait key

SELECT var=2

CASE 2:

`cls

PRINT "Bubbles rocks man! ";var

wait key

ENDCASE

ENDSELECT

`wait key

SELECT var=3

CASE 3:

`cls

PRINT "leave cory and trevor alone";var

wait key

ENDCASE

ENDSELECT

`wait key

SELECT var=4

CASE 4:

`cls

PRINT "this jim Lahey trailer park supervisor.";var

wait key

ENDCASE

ENDSELECT

`wait key

SELECT var

CASE 5:

`cls

PRINT "end the program exit man.";var

sleep 1500

end

ENDCASE

ENDSELECT

`wait key

`SELECT err

`CASE DEFAULT:
`PRINT "Only keys 1-5 work"
`ENDCASE
`ENDSELECT
`WAIT KEY



`// menu loop //
do

if keystate(2)=1 then inc var,1 `// for 1 key //
if keystate(3)=1 then inc var,2 `// for 2 key //
if keystate(4)=1 then inc var,3 `// for 3 key //
if keystate(5)=1 then inc var,4 `// for 4 key //

`// Update the screen Refresh rate //
sync

loop
end

Shay3000
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 9th Aug 2009 08:59
First you want to use code snips if you're entering code into a message. Type the following minus the spaces between the brackets:

[ code ]
Your code here.
[ /code ]

Do it right and we see this (just click on the box):


With INPUT you only use one variable at the end otherwise it will think you want to print to the screen the variables that come before the last variable.

When you do this:


It shows on the screen "Enter Number:1" and waits for the user to input var2. The user will always see a 1 they never entered (because before INPUT you have var1=1). If they hit 3 they'll see 13 as the menu choice.

SELECT statements are there for multiple choices. Creating 5 different SELECT/ENDSELECTs and looking for the variable var won't work because the INPUT command makes var2 equal whatever the user types so looking for var will never find the menu choices. Any variable that is used for the first time without being defined will always equal zero.

A SELECT/ENDSELECT should be done like this:


Also when you have SYNC ON it doesn't update the screen till it sees a SYNC... so when you PRINT something to the screen and have a WAIT KEY right after it the user won't see the text because there's no SYNC after the PRINT. Not using SYNC ON will always update the screen any time something changes.

When you use a DO/LOOP it keeps doing just what's within that DO/LOOP. So after the user types in the number and hits enter it goes by all the SELECT/ENDSELECTs then gets trapped in the DO/LOOP forever.

Inside the DO/LOOP you have it looking for the keys 1 through 4 and using the INC command. What INC does it adds to a variable... so if the user hits the 2 key it'll add 2 to the variable var. When the user hits 4 it adds another 4 to var. Because it's looping so fast var gets to be a huge number pretty quickly.

Try running this by itself to see what it's doing (hit the keys 1 through 4 of course):


Don't get discouraged by all the wrongness of your program. We all have to start somewhere.

Login to post a reply

Server time is: 2024-09-28 08:30:49
Your offset time is: 2024-09-28 08:30:49