I am New XD, Info Help
I am New XD, Info Help
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
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
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
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
REM Laser code
Laser:
mL = INT(RND * + 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
Laser:
mL = INT(RND * + 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
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
cool
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 , or an example would good as well
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Use a colon to combine the CASE with a single line of code:
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
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
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
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
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
(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
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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
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
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
sweet
O yea that is perfect that is excatly what i was looking for, thx a bunch
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?
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?
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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
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
Ted
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
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
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
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
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Using INKEY$ you can do it either way. The variable must be a string variable. "Y" or "N" would work too.
The loop will run until the proper answer is given unlike INPUT.
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.
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
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
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Such childishness! But they do bounce kinda nice.
Lord Necron has a harem! Already...
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
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
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...
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...
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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.
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
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