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.

DarkBASIC Discussion / Rnd code help

Author
Message
jkfde
13
Years of Service
User Offline
Joined: 6th Nov 2010
Location:
Posted: 19th Nov 2010 00:03
[/code]

for x = 1 to 1000
if object exist(x) = 1 then delete object x
if matrix exist(x) = 1 then delete matrix x
if mesh exist(x) = 1 then delete mesh x
if light exist(x) = 1 then delete light x
if x <= 32
if animation exist(x) = 1 then delete animation x
endif
next x

load image "Untitled1.bmp",11
load image "Untitled.bmp",10

make object sphere 11,50
scale object 11,600,600,250
rotate object 11,0,180,10

position object 11,235,0,10
texture object 11,10

make object box 12,10,520,1000
position object 12, 200,00,0
yrotate object 12,10
color object 12, rgb(255,255,0)

make object box 20,250,100,10
position object 20,200,155,235
yrotate object 20,90
color object 20,rgb(0,0,0)

make object box 21,250,50,10
position object 21,200,30,235
yrotate object 21,90
color object 21,rgb(0,0,0)

make object box 22,250,50,10
position object 22,200,-30,235
yrotate object 22,90
color object 22,rgb(0,0,0)


make object box 23,250,50,10
position object 23,200,-150,235
yrotate object 23,90
color object 23,rgb(0,0,0)


make object box 24,250,50,10
position object 24,200,-90,235
yrotate object 24,90
color object 24,rgb(0,0,0)


make object box 15,10,125,125
position object 15,75,15,00
color object 15,rgb(50,255,50)


make object box 16,10,125,125
position object 16,118,118,0
zrotate object 16,315
color object 16,rgb(255,50,50)
m=0
n=0
b=0
h=0
make object box 17,10,125,125
position object 17,118,-90,0
zrotate object 17,45
color object 17,rgb(255,50,50)
i=1
if i=1 then c=rnd(4)

do
if scancode() = 0 then exit
loop
do

if mouseclick()=1 and o=1 then w=1 : y=0

if mouseclick()=1 and m=1 then n=1

if i=1



v=c
if v=0
1q$="Question 1"
1a$="A) Answer 1"
1b$="B) Answer 2"
1c$="C) Answer 3"
1d$="D) Answer 4"
l=1
text 150,50,1q$
text 150,200,1a$
text 150,260,1b$
text 150,320,1c$
text 150,380,1d$
v=6
endif

if v=1
1q$="Question 2"
1a$="A) Answer 1"
1b$="B) Answer 2"
1c$="C) Answer 3"
1d$="D) Answer 4"
l=1
text 150,50,1q$
text 150,200,1a$
text 150,260,1b$
text 150,320,1c$
text 150,380,1d$
v=6
endif

if v=2
1q$="Question 3"
1a$="A) Answer 1"
1b$="B) Answer 2"
1c$="C) Answer 3"
1d$="D) Answer 4"
l=1
text 150,50,1q$
text 150,200,1a$
text 150,260,1b$
text 150,320,1c$
text 150,380,1d$
v=6
endif

if v=3
1q$="Question 4"
1a$="A) Answer 1"
1b$="B) Answer 2"
1c$="C) Answer 3"
1d$="D) Answer 4"
l=1
text 150,50,1q$
text 150,200,1a$
text 150,260,1b$
text 150,320,1c$
text 150,380,1d$
v=6
endif

if v=4
1q$="Question 5"
1a$="A) Answer 1"
1b$="B) Answer 2"
1c$="C) Answer 3"
1d$="D) Answer 4"
l=1
text 150,50,1q$
text 150,200,1a$
text 150,260,1b$
text 150,320,1c$
text 150,380,1d$
v=6
endif

endif
if l=1
if inkey$()="a"

i=0
o=1
y=1
l=0
endif

endif
if y=1
1q$="Correct! spin wheel (mouse click)"
1a$=" "
1b$=" "
1c$=" "
1d$=" "




text 100,50,1q$

text 150,200,1a$

text 150,260,1b$

text 150,320,1c$

text 150,380,1d$
endif




if w=1

color object 15,rgb(255,50,50)
color object 16,rgb(50,255,50)
color object 17,rgb(50,255,50)
texture object 11,11

wait 300


color object 15,rgb(50,255,50)
color object 16,rgb(255,50,50)
color object 17,rgb(255,50,50)
texture object 11,10
wait 300

color object 15,rgb(255,50,50)
color object 16,rgb(50,255,50)
color object 17,rgb(50,255,50)
texture object 11,11

wait 300

color object 15,rgb(50,255,50)
color object 16,rgb(255,50,50)
color object 17,rgb(255,50,50)
texture object 11,10
wait 300

color object 15,rgb(255,50,50)
color object 16,rgb(50,255,50)
color object 17,rgb(50,255,50)
texture object 11,11

wait 300

color object 15,rgb(50,255,50)
color object 16,rgb(255,50,50)
color object 17,rgb(255,50,50)
texture object 11,10
wait 300

color object 15,rgb(255,50,50)
color object 16,rgb(50,255,50)
color object 17,rgb(50,255,50)
texture object 11,11

wait 300

color object 15,rgb(50,255,50)
color object 16,rgb(255,50,50)
color object 17,rgb(255,50,50)
texture object 11,10
w=0
i=0
o=0
u=1

endif

if u=1
1q$="Question 2"
1a$="A) Answer 1"
1b$="B) Answer 2"
1c$="C) Answer 3"
1d$="D) Answer 4"

text 150,50,1q$

text 150,200,1a$

text 150,260,1b$

text 150,320,1c$

text 150,380,1d$

endif




REM MOVE CAMERA
cpZ# = Newzvalue(z#,ay-180,200)
cpX# = Newxvalue(x#,ay-180,200)
if cpX#<-19990 then cpX#=-19990
if cpZ#<-19990 then cpZ#=-19990
if cpX#>19990 then cpX#=19990
if cpZ#>19990 then cpZ#=19990
position camera -200,0,200
point camera 50.34,0,150

loop
[code]
I want it to randomly chose a question in the code. But since the v=rnd(4) is in the do loop it Shows all questions at once.

When ever i move the rnd(4) somewhere else it wont work

How can i get it to only show one question at random?

Please Help

-Thanks
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 20th Nov 2010 04:04 Edited at: 20th Nov 2010 04:06
Firstly, you have to put /code in the closing tag for the code box to work.

I assume you have just started programming, because you write the same way everyone does when they start; like your program is one long roll of parchment reading from top to bottom.
One of the first things you have to learn is to break down a complex idea into smaller tasks. When we learn maths, we learn the process, instead of trying to memorize every answer. Likewise to write an efficient program we must define procedures that can be repeated instead of rewriting similar code. Imagine if you wanted 1000 questions in your game, your program would be thousands of lines long!

Don't worry if you don't quite follow this I am writing it in a hurry, I or someone else will explain if you have any questions.

We make a quick plan, starting with the data we need:
* Questions
* Answers (four per question)
* A marker to tell the program which answer is correct

Since we want multiple questions and answers we will use an array.
An array is a group of variables, a bit like files in a filing cabinet where we can place a number in each file:
dim question$(14)
This array stores 15 strings (notice the $ in the name), it says 14 but always remember that you can store a value in 0 too!
So this is like a filing cabinet with 15 folders to store strings in, this is a one-dimensional array.

The answers require a two-dimensional array, because there is more than one answer per question.
dim answers$(14,3)
So in our filing cabinet there are 14 folders each with 3 files inside to store strings on.
I actually prefer to think of 2D arrays as a grid, the two numbers are like co-ordinates and we store our strings in grid squares.

The correct answer marker will also need an array
dim correct(14)
Notice this one doesn't have a $, that's because it stores integers, specifically the number of the correct answer (0-3).

We fill our arrays using the DATA command, it is very handy for filling arrays because it can be read sequentially like an external file.



Do oranges know what colour they are?
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 20th Nov 2010 05:52
An easy way to do your code is just to paste it into the post, then highlight it and click the code button.

Just a suggestion:
Use more obvious variable names. Variable names like c,v,i,o are all very ambiguous and it is impossible to know what is in each variable unless you trace through the code to find the line assigns it a value. By giving a variable a more descriptive name such as "QuestionNumber" or even just "Question" when you and others read your code, they know exactly whats going on, when its going on.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose

Login to post a reply

Server time is: 2024-03-28 12:06:55
Your offset time is: 2024-03-28 12:06:55