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 Professional Discussion / Scanning output text to compare with input text

Author
Message
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 18th Aug 2010 04:05
I am having a really tough time with this. I can set this up using about a million if statements, but I was wanting a faster way. It involves verb conjugation in Spanish. Here is how it will work:

"comer 2S" is displayed on the screen. The program scans the last two letters of comer and knows it is "er". It then goes to a set of values for "er". A seperate scan reads the "2S" and knows it is an "er" verb. The correct value for "2S" on an "er" verb is "es". The user needs to input "comes" for the correct answer.

Like I said, I can set this up using a BUNCH of if statements, but I might be dead before I finish coding it all. Is there a way to do this by scanning the output text?

www.dustinmcmurry.com
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Aug 2010 09:11
If you already know that the correct answer to "comer 2S" is "comes" then why have the program scan it at all? You could have both the question and the answer in an array loaded from a text file.

If you don't like using IF/THEN you can use SELECT/CASE instead.



Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 19th Aug 2010 00:17
I don't see how this code works for what I need. There isn't any user input to compare, and it looks to me like it is just changing the case of some text. When I run it it displays a bunch of random text.

www.dustinmcmurry.com
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Aug 2010 09:14
Quote: "I don't see how this code works for what I need. There isn't any user input to compare, and it looks to me like it is just changing the case of some text. When I run it it displays a bunch of random text."


It's just an example on how SELECT/CASE works. It's not showing random text it's showing what's in a$. I assumed you already had user input, the text extraction, and IF/THEN statements that could be changed into SELECT/CASE.

I'll ask some questions that may shed some light on your problem. How do you come up with displaying "comer 2S" on the screen? Does the user themselves enter "comer 2S" or does the program just display "comer 2S" to the user?

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 19th Aug 2010 20:18
Yes more info needed. Is the program reading a random or numbered list of questions? Or is it getting input from the user and converting? Does the user input an answer or a question or both?

http://s6.bitefight.org/c.php?uid=103081
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 20th Aug 2010 03:37
"comer 1S" is the question. the user needs to provide "comes" as the correct answer. There are 6 possible options. 1s=o,2s=es,3s=e,1p=emos,2p and 3p=en if the question word ends with er. o,as,a,amos,an if it ends with ar, and o,es,e,imos,en if it ends with ir.

The user needs to replace the last two letters of the word based on what those last two letters are and the other part (1s,2p,etc.) that is provided in the question.

www.dustinmcmurry.com
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 20th Aug 2010 04:49
If you control the questions then there's no need for complex code to extract the text to provide the answer. You only need to put the question and the answer in an array.

This is rather primitive but it does the job:


Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 20th Aug 2010 06:27
Yes, that works but I have over 100 words to do this with and each of them has 6 possible answers. I was hoping for a way to associate 1P with "emos" without entering each answer manually.

If the program could compare question word minus the last two letters to the user's answer plus the new ending (associated with 1P, 2S, etc.) it would save a TON of code.

www.dustinmcmurry.com
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 20th Aug 2010 06:28
Also I would like it to randomize the questions.

www.dustinmcmurry.com
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 20th Aug 2010 07:48
Rem Project: Dark Basic Pro Project
Rem Created: Thursday, August 19, 2010

Rem ***** Main Source File *****
a$="po"
b$="p"
do
cls
input "type the answer ";c$
cls
if c$=a$+b$ then print "good"
if c$<>a$+b$ then print "bad"

wait 3000
loop

www.dustinmcmurry.com
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Aug 2010 11:04 Edited at: 20th Aug 2010 11:06
As Grog says, an array would probably work best. You could put the information in data statements, like this:



Silverman
19
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 20th Aug 2010 12:11 Edited at: 20th Aug 2010 12:15
you can extract characters with these commands:



AMD Athlon(tm)XP 3200+ (2.2GHz) / DDR pc3200 (3x1024Mo) / Nvidia 6800GT (driver 197.45 WHQL)/ XP Pro SP3 / DirectX 9.0c (February 2010)/ DBClassic v1.2 / DBPro v7.4
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Aug 2010 12:35 Edited at: 20th Aug 2010 12:53
Here's a full version of what I was suggesting. All you have to do is put in the words and change the NumberOfWords variable.



Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 20th Aug 2010 15:24
Wow...that was insanely helpful. Thanks!

I didn't know I could do -2 with text. I should have, since I figured out I can add them together. So whatever number I put, that's how many characters it will delete?

www.dustinmcmurry.com
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 04:36
OK, so I figured the array thing out, and I added a score to it. But when I put in a timer, the timer stays at 5:00 forever. How do I get it to count down? randomize timer()

REM Put all the words into an array.
REM You will have much more than 10, correct?
NumberOfWords = 10
dim Words$(NumberOfWords)
for EachWord = 1 to NumberOfWords
read Words$(EachWord)
next EachWord

REM Your words. Obviously you will have many different words.
REM The NumberOfWords variable above must match how many words you have.
data "comer","hablar","decidir","preguntar","saltar"
data "correr","vomitar","recibir","partir","decidir"

REM Put the conditions in an array, you can choose one at random.
Dim Condition$(6)
for Condition = 1 to 6
read Condition$(Condition)
next Condition

REM Your possible conditions.
data "1S","2S","3S","1P","2P","3P"

REM Put the endings for each condition in an array.
NumberOfEndings = 3
dim PossibleEndings$(NumberOfEndings,7)

for Ending = 1 to NumberOfEndings
for Condition = 1 to 7
read PossibleEndings$(Ending,Condition)
next Condition
next Ending

REM 1s 2s 3s 1p 2p 3p ending
data "o", "es", "e", "emos", "en", "en", "er"
data "o", "as", "a", "amos", "an", "an", "ar"
data "o", "es", "e", "imos", "en", "en", "ir"

REM You now have an array that has 7 elements for each ending:
REM Elements 1 - 6 are the proper endings for each condition.
REM Element 7 is the 2 letter ending to check agains each word.

REM Your main loop.
do
cls
set text size 50
print "Score: "; score
if bonus=0 then bonus=1
print "Multiplier: "; bonus

REM Choose a random word.
REM (The -1 and +1 are there simply because I don't
REM like using element zero for numbered lists of things.)
Question$ = Words$(rnd(NumberOfWords-1)+1)





REM Choose a random condition for the question.
REM This is a random number between zero and 5.
REM Adding one gives a range of one to six.
Condition = rnd(5)+1

REM Construct the correct answer for this word
REM and condition, by replacing the last two
REM characters of the word with the proper ending

REM Determine the last two characters.
LastTwo$=right$(Question$,2)

REM Find the correct ending for the condition.
select LastTwo$
case "er":
CorrectEnding$=PossibleEndings$(1,Condition)
endcase

case "ar":
CorrectEnding$ = PossibleEndings$(2,Condition)
endcase

case "ir":
CorrectEnding$ = PossibleEndings$(3,Condition)
endcase

case default:
endcase
endselect

set text size 12
REM Construct the correct answer.
Answer$ = left$(Question$, len(Question$)-2) + CorrectEnding$

REM Ask the question.

ink rgb(200,200,200),0
print " "
print " What is the ";Condition$(Condition);" form of ";
ink rgb(255,255,255),0
print Question$;
ink rgb(200,200,200),0
input "? ",StudentAnswer$

REM Convert to lower case for an exact match.
StudentAnswer$ = lower$(StudentAnswer$)

REM Check the answer and keep score.
if StudentAnswer$ = Answer$
ink rgb(0,255,0),0
print " Correct!"
inc CorrectAnswers
inc correct
if correct=5 then multiplier=multiplier+1;correct=0
if multiplier>7 then multiplier=multiplier^2
if multiplier>5 then bonus=(1 + (multiplier^2))^2
if multiplier<6 then bonus=1 + (multiplier^2)
score=score + (500*bonus)

else
ink rgb(255,0,0),0
print " Wrong!"
ink rgb(200,200,200),0
print " The correct answer is ";
ink rgb(255,255,255),0
print Answer$
inc WrongAnswers
bonus=0
multiplier=0
endif

REM Display the score and pause until a key is pressed.
ink rgb(200,200,200),0
print " Your score so far is ";CorrectAnswers;" correct and ";WrongAnswers;" wrong"
wait 2000
loop

www.dustinmcmurry.com
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 04:37
And...how do I make a snippet? I clicked on "code"...

www.dustinmcmurry.com
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 21st Aug 2010 07:10 Edited at: 21st Aug 2010 07:23
Quote: "But when I put in a timer, the timer stays at 5:00 forever. How do I get it to count down?"


Using the INPUT command stops all action till the user hits enter. The only way to actually put in a timer is to make your own user input routine using ENTRY$().

Using ENTRY$() is a better method because it allows you to control every aspect of the user input like not allowing certain keys, controlling how fast things move (with timers), what the prompt looks like, how many characters to allow the user to type in, the colors during the input, and much more.



Quote: "And...how do I make a snippet? I clicked on "code"..."


To do code snips you type (without the spaces):
[ code ]
Your code here.
[ /code ]

It'll look like this:


There is also a code snip that colors the text when you want actual code in the snip (again without the spaces) (the dbp = Darkbasic Pro):
[ code lang=dbp ]
print "This is colored."
[ /code ]

It looks like this:


Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 20:50
But wouldn't the timer adjust after the input is given by user? Mine stays at 5:00 forever, even after I put in an answer.

Either way, if the other command is better I should probably switch it.

www.dustinmcmurry.com
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Aug 2010 21:12 Edited at: 21st Aug 2010 21:23
Well, the timer doesn't really stop running when you are waiting for an input, but you can't display the timer while you are waiting for the user to respond to INPUT.

What are you wanting to accomplish? If you just want to know how long the user took you can store the timer value before you ask the question, then compare the current timer value after the question is answered. The difference will be how long (in milliseconds) the user took to answer.

If you want to keep track of the time while the user is answering, Grog's solution should let you do that as well.

Here is a version of my solution that keeps track of how long it took to answer the question...



Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 21:22
I want the game to last for five minutes and then end. I would also like the time remaining to be visible. When I put it in I end up with a permanent five minute display.

Also, I changed input to an entry$ command and I cannot input any answers...grr, I hate my noobishness.

www.dustinmcmurry.com
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Aug 2010 21:27 Edited at: 21st Aug 2010 21:28
Quote: "I want the game to last for five minutes and then end. I would also like the time remaining to be visible. When I put it in I end up with a permanent five minute display."


I see. Then my "hit any key to continue" wouldn't work either, since you can't display the clock while "wait key" is, well, waiting.

I'm at work, but biz is slow, so I might be able to adapt my code to do what you want, give me a few minutes...

Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 21:41
OK....I had a piece out of place, as now I can have a successful timer that counts UP...need one that counts down.

www.dustinmcmurry.com
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 21:45
I'm OK with it not having a live display of the clock, that's just bonus. I have it lasting five minutes. Problem was T=timer() was in the wrong spot.



www.dustinmcmurry.com
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Aug 2010 22:04 Edited at: 21st Aug 2010 22:05
Great!

5 minutes is 300 seconds, or 300000 milliseconds.

So your value to use for a countdown would be something like



and then convert TimeLeft into the clock format.

Assuming the program is not run in the five minutes before/after midnight, when the timer resets.

EDIT: Alright! You doing good!

Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 21st Aug 2010 22:29
Thanks. You have been extremely helpful. I might even have this thing up and running this weekend.

Right now it is functional as a learning tool, but I'd like to polish it. I'm competing with HALO for my kids' attention, so this black screen doesn't quite get there. Thanks again!

www.dustinmcmurry.com
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 21st Aug 2010 23:07
@Igglepud - I know what you mean! I made a geography program for my nephew to learn state capitals, and I had to fancy it up a lot to keep his attention.

Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 23rd Aug 2010 05:48
Just noticed this got over 10k views...didn't know text was such a hot topic.

www.dustinmcmurry.com
Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 27th Aug 2010 02:46


Why isn't the timer working correctly? I know it is because T is constantly being set to 1. But when I change it to a variable based on T, the countdown goes into the negatives in about 2 seconds. It counts down at my PC clock speed rather than in seconds.

www.dustinmcmurry.com
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 27th Aug 2010 06:07 Edited at: 27th Aug 2010 06:10
On this line:


You make T equal the current timer() minus the current timer() divided by 1000 and add 1. When you subtract the current timer() from the current timer() you get zero. You need a starting time that's set outside of the loop and within the loop you subtract the current timer() from the old timer() to be able to determine how many seconds have gone by.

One of the things that makes it easier for yourself and the rest of us is indenting. Indenting is when you use spaces before each line to make the code easier to read. What we do is we indent anything inside loops and conditions DO/LOOPs, FOR/NEXT, REPEAT/UNTIL, WHILE/ENDWHILE, IF/ENDIF, SELECT/CASE. Most people use TAB but I only use one space. It helps us to know when the beginning of a loop or condition is and when it ends. Also don't be afraid of using blank lines to separate things. Always use REM statements so you can know what's going on in your code. If you stop working on your code and go back to it a month or two later, a year later, or several years later you need only to look at the REM statements (shortened to ` ) to get what's going on in your code. REM statements and blank lines do not slow down or harm the program in any way.

A quick indenting example:


Here's your code fixed:


Edit: I see you have been using REM statements... so keep up the good work and start indenting.

Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 29th Aug 2010 16:00 Edited at: 29th Aug 2010 17:37


OK, it is working for the first minute. Then for some reason it freezes the seconds and runs minutes down to negative infinite.

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 29th Aug 2010 17:24
Yikes, fix that post!

Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 29th Aug 2010 17:37
All better.

Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 30th Aug 2010 05:59
By all better, I mean my post is fixed. My timer is still broken...

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Aug 2010 08:29 Edited at: 30th Aug 2010 08:32
You really need to stop using semicolon ( ; ) to separate commands. You should be using colon instead ( : ). Any time you use ; instead of : you're asking for trouble. ; is only ok after a PRINT statement.

It's easier just to reset the StartTime rather than try to calculate the current seconds vs all the seconds gone by. There's also no need to complicate it by resetting the seconds because they will automatically be reset when the StartTime is reset.



Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 2nd Sep 2010 05:23
OK, I did that but the clock keeps going negative. I'm assuming here I need to tell it to end the program elsewhere...should be an easy fix.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 3rd Sep 2010 05:47
Yeah, I didn't bother adding code to stop the clock when the minutes are up. You can add it within the check for the seconds



Igglepud
15
Years of Service
User Offline
Joined: 14th Aug 2010
Location:
Posted: 3rd Sep 2010 06:00 Edited at: 3rd Sep 2010 06:00
I did. Thanks for checking on it though. I've got this thing done. Just need to add more questions to the program and I'm set.

Then I get to move on to phase two...different tenses. Ugh...I think I might set it up with 2 data strings instead, one english and the other spanish. It's a heck of a lot easier to do it that way (I think). Below is an example I have working in the other format.

http://dustinmcmurry.com/stemonator.exe

Login to post a reply

Server time is: 2026-07-23 04:54:34
Your offset time is: 2026-07-23 04:54:34