I am New XD, Info Help

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Anonymous

I am New XD, Info Help

Post by Anonymous » Sat Dec 05, 2009 12:45 pm

Hi all, Iam new to qbasic and have been programming for only a week now i have made a random generater to make things interesting for me for a certain game i play, i need some tips i well post my current program
i have is there an easier way to get more info in or easier to access it with so many lines of code? help plz :D

Anonymous

Post by Anonymous » Sat Dec 05, 2009 12:50 pm

CLS

RANDOMIZE TIMER

DO WHILE q < 4
RANDOMIZE TIMER
q = q + 1
x = INT(RND * 12) + 1
IF x = 1 THEN GOSUB Prowler
IF x = 2 THEN GOSUB Jujuman
IF x = 3 THEN GOSUB Vypor
IF x = 4 THEN GOSUB Livewire
IF x = 5 THEN GOSUB Rouge
IF x = 6 THEN GOSUB Manticore
IF x = 7 THEN GOSUB Kouger
IF x = 8 THEN GOSUB Jackhammer
IF x = 9 THEN GOSUB Ronin
IF x = 10 THEN GOSUB Valient
IF x = 11 THEN GOSUB Irondeath
IF x = 12 THEN GOSUB Raptor
PRINT " "
SLEEP 1
LOOP

REM Restart Chain
INPUT "Generate Again 1.Yes, 2.No? ", a1
IF a1 = 1 THEN CHAIN "test3.bas"
IF a1 = 2 THEN END

END

REM Prowler code
Prowler:
PRINT "Prowler";

REM Random Generator
px = INT(RND * 3) + 1
py = INT(RND * 3) + 1

REM Weapon List
IF px = 1 THEN PRINT TAB(15); "Laser";
IF px = 2 THEN PRINT TAB(15); "Assault";
IF px = 3 THEN PRINT TAB(15); "Shotgun";
IF py = 1 THEN PRINT TAB(30); "Rocket"
IF py = 2 THEN PRINT TAB(30); "Missle"
IF py = 3 THEN PRINT TAB(30); "Large Missle"
IF px = 1 THEN GOSUB Laser
IF px = 2 THEN GOSUB Assault
IF px = 3 THEN GOSUB Shotgun
IF py = 1 THEN GOSUB Rocket
IF py = 2 THEN GOSUB Missle
IF py = 3 THEN GOSUB LargeMissle
RETURN
END

REM Jujuman code
Jujuman:
PRINT "Jujuman";

jx = INT(RND * 3) + 1
jy = INT(RND * 3) + 1

REM Weapon List
IF jx = 1 THEN PRINT TAB(15); "Laser";
IF jx = 2 THEN PRINT TAB(15); "Assault";
IF jx = 3 THEN PRINT TAB(15); "Shotgun";
IF jy = 1 THEN PRINT TAB(30); "Rocket"
IF jy = 2 THEN PRINT TAB(30); "Missle"
IF jy = 3 THEN PRINT TAB(30); "Large Missle"
IF jx = 1 THEN GOSUB Laser
IF jx = 2 THEN GOSUB Assault
IF jx = 3 THEN GOSUB Shotgun
IF jy = 1 THEN GOSUB Rocket
IF jy = 2 THEN GOSUB Missle
IF jy = 3 THEN GOSUB LargeMissle
RETURN
END

Anonymous

Post by Anonymous » Sat Dec 05, 2009 12:51 pm

REM Laser code
Laser:

mL = INT(RND * 8) + 1
IF mL = 1 THEN PRINT TAB(15); "MT-OscillatorA";
IF mL = 2 THEN PRINT TAB(15); "MT-OscillatorB";
IF mL = 3 THEN PRINT TAB(15); "GL-OscillatorA";
IF mL = 4 THEN PRINT TAB(15); "GL-OscillatorB";
IF mL = 5 THEN PRINT TAB(15); "CL-OscillatorA";
IF mL = 6 THEN PRINT TAB(15); "CL-OscillatorB";
IF mL = 7 THEN PRINT TAB(15); "HM-OscillatorA";
IF mL = 8 THEN PRINT TAB(15); "HM-OscillatorB";
RETURN
END

REM Assault code
Assault:

mA = INT(RND * 12) + 1
IF mA = 1 THEN PRINT TAB(15); "80 AP";
IF mA = 2 THEN PRINT TAB(15); "140 AP";
IF mA = 3 THEN PRINT TAB(15); "200 AP";
IF mA = 4 THEN PRINT TAB(15); "80 DFAP";
IF mA = 5 THEN PRINT TAB(15); "140 DFAP";
IF mA = 6 THEN PRINT TAB(15); "200 DFAP";
IF mA = 7 THEN PRINT TAB(15); "80 CHEM";
IF mA = 8 THEN PRINT TAB(15); "140 CHEM";
IF mA = 9 THEN PRINT TAB(15); "200 CHEM";
IF mA = 10 THEN PRINT TAB(15); "80 HDAP";
IF mA = 11 THEN PRINT TAB(15); "140 HDAP";
IF mA = 12 THEN PRINT TAB(15); "200 HDAP";
RETURN
END

REM Shotgun code
Shotgun:

mS = INT(RND * 12) + 1
IF mS = 1 THEN PRINT TAB(15); "50 AP";
IF mS = 2 THEN PRINT TAB(15); "70 AP";
IF mS = 3 THEN PRINT TAB(15); "100 AP";
IF mS = 4 THEN PRINT TAB(15); "50 HD";
IF mS = 5 THEN PRINT TAB(15); "70 HD";
IF mS = 6 THEN PRINT TAB(15); "100 HD";
IF mS = 7 THEN PRINT TAB(15); "50 CR";
IF mS = 8 THEN PRINT TAB(15); "70 CR";
IF mS = 9 THEN PRINT TAB(15); "100 CR";
IF mS = 10 THEN PRINT TAB(15); "50 HDAP";
IF mS = 11 THEN PRINT TAB(15); "70 HDAP";
IF mS = 12 THEN PRINT TAB(15); "100 HDAP";
RETURN
END

REM Rocket Code
Rocket:

sR = INT(RND * 5) + 1
IF sR = 1 THEN PRINT TAB(30); "Snake"
IF sR = 2 THEN PRINT TAB(30); "Hercules"
IF sR = 3 THEN PRINT TAB(30); "Nighthawk"
IF sR = 4 THEN PRINT TAB(30); "Panther"
IF sR = 5 THEN PRINT TAB(30); "DragonFly"
RETURN
END

Anonymous

XD

Post by Anonymous » Sat Dec 05, 2009 12:52 pm

There sry could not upload file for some reason but thats some it ima sure you get it XD

User avatar
Brandon
Coder
Posts: 47
Joined: Sat Nov 19, 2005 9:24 pm
Location: NY
Contact:

Post by Brandon » Sat Dec 05, 2009 2:26 pm

One tip I have is using SELECT CASE instead of tons of IF statements, here is an example based off your first list of IFs:

Code: Select all

SELECT CASE x
CASE 1
    GOSUB Prowler
CASE 2
    GOSUB Jujuman
CASE 3
    GOSUB Vypor
CASE 4
    GOSUB Livewire
CASE 5
    GOSUB Rouge
CASE 6
    GOSUB Manticore
CASE 7
    GOSUB Kouger
CASE 8
    GOSUB Jackhammer
CASE 9
    GOSUB Ronin
CASE 10
    GOSUB Valient
CASE 11
    GOSUB Irondeath
CASE 12
    GOSUB Raptor 
END SELECT

Anonymous

cool

Post by Anonymous » Sat Dec 05, 2009 5:50 pm

Cool ill try that, also is there a way to store information or words in some kind of command or like an array and give them a number so it can be easliy recalled and then printed out on the screen?, if so waht commands are used for this so i can study them :D, or an example would good as well :D

User avatar
burger2227
Veteran
Posts: 2419
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Sat Dec 05, 2009 6:07 pm

Use a colon to combine the CASE with a single line of code:

Code: Select all

SELECT CASE x 
CASE 1: GOSUB Prowler 
CASE 2: GOSUB Jujuman 
CASE 3: GOSUB Vypor 
CASE 4: GOSUB Livewire 
CASE 5: GOSUB Rouge 
CASE 6: GOSUB Manticore 
CASE 7: GOSUB Kouger 
CASE 8: GOSUB Jackhammer 
CASE 9: GOSUB Ronin 
CASE 10: GOSUB Valient 
CASE 11: GOSUB Irondeath 
CASE 12: GOSUB Raptor 
END SELECT
If you need more than one code line, a block, then the first line still can use a colon after the CASE.

Your next question is kind of vague. Please explain what you need to accomplish.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Anonymous

Post by Anonymous » Sun Dec 06, 2009 11:12 am

Cool thx that has made things a litte easier to handle ok for my last qeustion ill try to amke an example of what i want to do its not code XD, like i want to make something that stores data ora command then give it a value so it can easly be recalled something like this

(command) To, For, Us, The, Etc.....

As i said before give each one a value like 1,2,3,4,etc....
so it comes out like this

Read 1 (since 1 is To)
Print 1 ( so it well print To on the screen)

Then i want to make it random like only it certerin portaions of that code,
something like this

x1 = (command)(then random forom like 3-5 so it only print words from value 3, 4, or 5.
Print x1

thats what ima trying to do, ive been reading commands ill admit iam not understanding all of them, let me know if iam making any sense......I hope XD

User avatar
burger2227
Veteran
Posts: 2419
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Sun Dec 06, 2009 8:14 pm

Unfortunately Arrays are not listed in the QB help index.

Arrays can hold more than one value. The values are assigned and read by referring to an index number.
Just make up a name for it:

DIM Arrayname(100) AS STRING ' creates a string array that can hold 100 strings

Arrayname(1) = "TO " ' assigns text to the array at index 1
Arrayname(2) = "BE "
Arrayname(3) = "OR "
Arrayname(4) = "NOT "

PRINT Arrayname(1) + Arrayname(2) + Arrayname(3) + Arrayname(4) + Arrayname(1) + Arrayname(2)

PRINTS: TO BE OR NOT TO BE

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Anonymous

sweet

Post by Anonymous » Mon Dec 07, 2009 4:06 pm

O yea that is perfect that is excatly what i was looking for, thx a bunch :D

Next question XD, the random function is there a way to amke it random between 2 numbers? couse i know this code gives 1-20

x = INT(RND * 20) + 1

I want to make it so it only goes random from numbers 10-20
is there a way to do that?

User avatar
burger2227
Veteran
Posts: 2419
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Mon Dec 07, 2009 4:44 pm

INT always rounds down to the next lower integer value. Even with negative values. So you add 1.

max is the maximum you need and min is the minimum number.

INT formula: randNum = INT(RND * (max - min + 1)) + min

Code: Select all


Using a 10 to 20 example: 

randNum = INT(RND * (20 - 10 + 1)) + 10

randNum = INT(RND * 11) + 10 

INT(RND * 11) will end up giving you an integer from 0 through 10 (11 is excluded).
Adding 10 to each of those numbers will give you 10 through 20, just as you wanted.

Using negatives values from -2 to -12 in the formula. Max is less negative:

max = -2: min = -12

Code: Select all

randNum = INT(RND * (-2 + 12 + 1)) - 12

randNum = INT(RND * 11) - 12
Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Anonymous

ok

Post by Anonymous » Tue Dec 08, 2009 9:50 am

Awsome ima gona try and fisnsh my program now XD thx a bunch

Anonymous

dang

Post by Anonymous » Tue Dec 08, 2009 10:00 am

*Sigh* guess not, ok

when i have the computer ask a question, i want to be able to answer back as yes or no can i do that or does it have to have a value like 1.yes, 2.no?

User avatar
burger2227
Veteran
Posts: 2419
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Tue Dec 08, 2009 12:49 pm

Using INKEY$ you can do it either way. The variable must be a string variable. "Y" or "N" would work too.

Code: Select all

PRINT "Do you want to play again? (Y/N): "; ' use semicolon at end
DO
again$ = UCASE$(INKEY$) ' converts keypress to uppercase letters
LOOP UNTIL again$ = "Y" OR again$ = "N"
PRINT again$ ' prints at end of question above.
The loop will run until the proper answer is given unlike INPUT.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

User avatar
bongomeno
Veteran
Posts: 231
Joined: Wed Dec 10, 2008 9:08 am
Location: San Bernardino CA
Contact:

Post by bongomeno » Tue Dec 08, 2009 2:13 pm

lol @ your signature :lol:
Home: http://www.geekbasic.com" target="_blank
Forum: http://www.geekbasic.com/index.gbws?$page=forumsmain" target="_blank
QB64 powered web server: http://www.geekbasic.com/index.gbws?$pa ... inter=%201" target="_blank

User avatar
burger2227
Veteran
Posts: 2419
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Wed Dec 09, 2009 3:36 am

Such childishness! But they do bounce kinda nice.

Lord Necron has a harem! Already...
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Anonymous

XD

Post by Anonymous » Wed Dec 09, 2009 1:27 pm

Lol XD

Anonymous

Post by Anonymous » Wed Dec 09, 2009 1:49 pm

Lol again, casue ima an idiot XD

how do i get arrow keys to work, right now iam using A,S,D,W but using those kinda interferas with the program iam trying to make, i need those keys for something else, i would like to use the arrow keys for movment like up down, left right



The harem gives me strenght...

User avatar
burger2227
Veteran
Posts: 2419
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 » Wed Dec 09, 2009 4:21 pm

Using INKEY$ the codes are two byte codes with the first always being CHR$(0).

CHR$(0) + CHR$(72): Up Arrow key,
CHR$(0) + CHR$(75): Left Arrow key"
CHR$(0) + CHR$(77): Right Arrow key,
CHR$(0) + CHR$(80): Down Arrow key"

Use SELECT CASE to use them. Change coordinate values in the CASE making sure not to go beyond the screen width and depth.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Post Reply