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 / A function or Array or what?

Author
Message
exceed beyond
19
Years of Service
User Offline
Joined: 7th Feb 2007
Location:
Posted: 12th Feb 2007 14:58
I am trying to make a bible trivia game, but I dont know how to program the code to:

PULL RANDOM question from array or function
ASK NEW QUESTION
DONOT ASK THIS Question for a really long time.

I dont expect you to give me all the answers, as i would like to see how it works. a starting place would be appeciative. like should i use an array or function or any tips to optimize code. thx
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Feb 2007 19:06


TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Feb 2007 20:10
Your biggest problem will be deciding if what the user entered is correct or not.

For example, say you have the following question:

What date is Christmas day?

Your answer is stored as 25 December.

What if the user types December 25, December 25th or 25th of December?

All are correct, but as none are exactly the same as your specified answer it will be flagged as incorrect.

It might therefore be worth considering a multiple choice version where each question can be answered with a, b, c or d.

You will have to type a lot more answers in, but at least your program knows that there is only one correct answer and what it is.

One method of doing this would be to create an array like Questions$(1000,6) which allows for up to 1000 questions. The second array element (6) would be used for the following:

Questions$(1,0) - The question
Questions$(1,1) - Answer option 1
Questions$(1,2) - Answer option 2
Questions$(1,3) - Answer option 3
Questions$(1,4) - Answer option 4
Questions$(1,5) - The number of the correct answer (1 - 4)
Questions$(1,6) - Whether the question has been answered correctly or not

(All the data would be loaded in from an external file).

So your program would print Questions$(QNum,0) then print the four answer options Questions$(QNum,1), Questions$(QNum,2), Questions$(QNum,3) and Questions$(QNum,4).

Questions$(QNum,5) would be checked to see which one of the four options is the correct answer.

Questions$(QNum,6) would initially be left empty, but you would set that element of the array to "Y" to denote that the question has been answered correctly or "N" to say it was answered incorrectly.

When you randomly select a question, if Questions$(QNum,6) is empty or "N" then ask the question. If it's "Y" then don't ask the question.

This allows questions can be asked again and again until they are answered correctly then not asked again.

TDK_Man

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Feb 2007 11:56
I just assumed he wanted a system like flash cards or something, leaving it up to the user to decide if his answer was close enough or not.

exceed beyond
19
Years of Service
User Offline
Joined: 7th Feb 2007
Location:
Posted: 13th Feb 2007 12:51
i like both of the options. thx!!! really
exceed beyond
19
Years of Service
User Offline
Joined: 7th Feb 2007
Location:
Posted: 13th Feb 2007 14:07
Hey TDK

if info is being loaded from an external file why would i need an array? couldnt i jus compare the inputted data from user to data in the file.
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Feb 2007 18:13 Edited at: 13th Feb 2007 18:13
Phaelax:

I wasn't trying to correct what you suggested - I was just pointing out possible problems he might encounter, whatever method he used.

Quote: "if info is being loaded from an external file why would i need an array"


External files are sequential in DB - you can't seek to a random question. So, you load all the questions into an array and access them randomly from there.

Plus you have the ability to 'mark' read ones as described in my post and as one array holds the question, answer(s) and whether it's been asked before or not, it just makes the whole thing so much easier to handle.

You'd even use arrays with the flashcard version that Phaelax demonstrated.

TDK_Man

exceed beyond
19
Years of Service
User Offline
Joined: 7th Feb 2007
Location:
Posted: 14th Feb 2007 12:31
oh ok TDK. thx for the clarification. i checked out your website. things were explained very clear, easy to follow. I would like to see alot of those "To follow" links also. happy coding.

Login to post a reply

Server time is: 2026-07-07 01:53:22
Your offset time is: 2026-07-07 01:53:22