2017-10-23 07:42:50

Hi guys!
I hope you can help me with my problem.
How can i randomize two questions in bgt?
Here is my code:
void main()
{
string input;
input=input_box("input_box", "what is bgt?", "");
if(input=="a programming language")
{
alert("yes!", "The answer was indeed a programming language!");
}
else
{
alert("Sorry!", "The answer is a programming language, not "+input+"!");
}
string input1;
input1=input_box("input_box", "what does tts mean?", "");
if(input1=="text to speech")
{
alert("yes!", "The answer was indeed text to speech!");
}
else
{
alert("Sorry!", "The answer is text to speech, not "+input1+"!");
}
}
Thanks for your help.
Best regards.

2017-10-23 12:54:02

If I understand correctly, you probably want two arrays: one with the questions, and the other with the answers.
You'd have answers[0] be the answer to questions[0], answers[1] for questions[1], etc.
Then you'd create a random int to decide which question to show. Ex, int index = random(0, questions.length()-1);
Then your input_box would take questions[index] where you'd normally put the answer.

if(answers[index]==input) alert("Correct!", "You\'re right!");
Hth

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-23 20:11:59

@CAE_Jones
Thank you. Can you explain what I have to do step by step?
What is a good programming language to write vocabularies with the random function?

2017-10-23 20:36:01

Something like this (replace the questions and answers as you wish):

void main() {
    int size=3; // Or however many questions you want.
    string[] questions(size);
    string[] answers(size);
    questions[0] = "Say hello.";
    answers[0] = "hello";
    questions[1] = "What color is the sky?";
    answers[1] = "blue";
    questions[2] = "How many licks does it take to get to the Tootsy Roll center of a Tootsy Pop?";
    answers[2] = "3 if you're an owl";
   
    // now, pick one:
    int index = random(0, size-1);
    string text = input_box(questions[index], "Your answer:");
    // Just to be safe, let's make sure the answer and input are the same case:
    text = string_to_lower_case(text);
    if(text == answers[index]) {
        alert("Correct!", "You gave the correct response!");
    }
    else {
        alert("Incorrect!", "That is not the right answer!");
    }
}

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-23 21:23:14

@CAE_Jones:
Have you tried out the program? The program randomizes nothing at all. When I put this line into my code:
int index = random(1, size-1);
the program only presents the first question.
I wanted the program to randomize questions[0] questions[1] and questions[2].

2017-10-23 21:53:22 (edited by CAE_Jones 2017-10-23 22:08:30)

You want random (0, size-1), and size must be greater than 0.
I typed the example on my phone, so haven't tested it yet.  reading it again, nothing jumps out at me as likely to break it. Have you tried it exactly as written? If it compiles, how many times did you run it without any change?
There might be some number typo somewhere, but I still haven't found it.

[edit] Yeah, I tested it, and it works perfectly on my computer. It took running it 5 times to get all 3 questions. Remember that for the random function, the first value must be smaller than the second value. Also, arrays are 0-based.[/edit]

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-24 05:37:51

@CAE_Jones:
Thank you. Can bgt only play *.wav files or can it also play *.ogg files?
I wanted bgt to randomize all three questions, so when I answer one question, he program proceeds with the second question and so on, until all three questions are answered correctly.

2017-10-24 12:37:06

Yes, BGT can play .ogg files. If you want to do a non-repeating random sequence, that's a bit more complicated.
You could accomplish this in several different ways. For example, you could have a third array, this one of bools, and do something like this:

bool[] shown(size);
// Don't assume it will initialize to all false:
for (uint i=0; i<size; i++) {

 shown[i]=false; 

}
string text="−";
while (text != "") // allow the user a way to quit early.
{
int index=random(0, size-1);
  while (shown[index])
  {
   // check to see if we're done:
   bool done=true;
   for (uint i=0; i<size; i++) {
   

if(!shown[i]) done=false;

   }
   if (done) index=-1;
   else index=random(0, size-1);
   if (done) break;
  }
  if (index<0) break;
  text = input_box(question[index], "Your answer:");
  if (text=="" or text=="quit") break;
  // Ignore case:
  text=string_too_lower_case(text);
  if (answers[index]==text)
  {
   shown[index] = true;
   alert("Correct!", "That is the correct response!");
  }
  else
  {
   alert("Incorrect!", "That is not correct!");
  }
}
alert ("That\'s all!", "Thanks for playing!");

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-24 18:42:43

@CAE_Jones:
Thank you for the code.
*.ogg files aren't working for me. Only *.wav files work.

How is it possible to implement nvda in bgt?
When I type:
#include "license.txt"
#include "nvdaControllerClient32.dll"
bgt sends an error. How can I fix this?

2017-10-24 20:48:12

You don't need to include license.txt, just the nvda controller client dll.
I'm not sure what's up with the ogg issue. Can you paste an example that doesn't work?

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-24 21:21:32

@CAE_Jones:
I tried playing *.ogg files with bgt and it worked. Can bgt only play *.ogg files?

I tried including nvda and it gave me an compilation error:
File: C:\Program Files (x86)\BGT\include\nvdaControllerClient32.dll
On line: 1 (3)
Line: MZÿÿ¸@غ´    Í!¸LÍ!This program cannot be run in DOS mode.

Error: Expected identifier

File: C:\Program Files (x86)\BGT\include\nvdaControllerClient32.dll
On line: 1 (3)
Line: MZÿÿ¸@غ´    Í!¸LÍ!This program cannot be run in DOS mode.

Error: Instead found '<unrecognized token>'

What am I doing wrong?

2017-10-24 22:00:24

You don't need to include the dll, just use the screen_readerlesset_library_path funtion (I forget what it's called, but it's in the manual near the screen_reader_speak function).
BGT plays .wav and .ogg. You would need external libraries to play other filetypes.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-24 22:54:12

@CAE_Jones:
When I try playing wav files in bgt, bgt plays no sound at all. When I include a *.ogg file, it plays the sound.

2017-10-24 23:06:26

BGT does have issues with wav files of certain bitdepths. Specifically, I think it only plays wavs with bitdepths that are powers of 2 (8, 16, 32), but not 24 or 36, etc. Maybe try playing c:\\windows\\media\\ding.wav, since that one always works. That file got kinda quiet post-xp, so if you want something louder, chord.wav is also reliable.
If you can't get it to play ding or chord, then there is a very strange problem to be solved.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-10-25 07:24:51

@CAE_Jones:
ding.wav and chord.wav are working fine. But other *.wav files aren't working. Is it better to use *.ogg files instead?

2017-10-29 18:11:17

Hello.
To solve this problem, you need to do the bit dept conversion on some audio editor that supports this feature, as in Soundforge itself.
convert the bit dept from the file to 16 bits, which is the most used currently and bgt will play them.
this is quite common with sound files from professional libraries, in which all files were written to 24 bit wav.

2017-10-31 08:00:30

Hello.
Thank you for your help.