Table contains value?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • StealthFD
    Indigo Rose Customer
    • Apr 2004
    • 47

    Table contains value?

    Having an issue trying to figure out how to see if a value exisits in a table.

    I am randomizing a test/quiz app and I'm pretty sure I'm on the right track here -
    #1. create a temp table to store the used question numbers in
    #2. generate a random number
    #3a. IF that number is not in the table, THEN do some stuff and write that question number into the temp table - OR
    #3b if that number is in the table GOTO #2

    I just can't seem to figure out how to check to see if a table contains a value... or how to "GOTO #2"

    Code:
    random_question = Math.Random(10);
    if (table.used_q does not contain random_question) then
    	Paragraph.SetText("a_box", Question_Bank[random_question].A);
                 Paragraph.SetText("q_box", Question_Bank[random_question].Q);
                 table_row = table_row + 1;
                 Table.Insert(used_q, table_row, random_question);
    else
    	loop back to random_question generation
    end
    Can someone point me to an example please?

    Thanks guys!
    - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    #2
    StealthFD,

    I built a quiz engine that would randomize a test and the answers. (1) In short what I did was have a temporary master table that contained all the questions and answers. (2) I would then use a for loop to build a table with the number of question I want to ask and to generate a random number that will be the index for the question pulled from the temporary master table. That question was then placed in the test to be given table as the next question in line.

    HTH
    Tigg

    Originally posted by StealthFD
    Having an issue trying to figure out how to see if a value exisits in a table.

    I am randomizing a test/quiz app and I'm pretty sure I'm on the right track here -
    #1. create a temp table to store the used question numbers in
    #2. generate a random number
    #3a. IF that number is not in the table, THEN do some stuff and write that question number into the temp table - OR
    #3b if that number is in the table GOTO #2

    I just can't seem to figure out how to check to see if a table contains a value... or how to "GOTO #2"

    Code:
    random_question = Math.Random(10);
    if (table.used_q does not contain random_question) then
    	Paragraph.SetText("a_box", Question_Bank[random_question].A);
                 Paragraph.SetText("q_box", Question_Bank[random_question].Q);
                 table_row = table_row + 1;
                 Table.Insert(used_q, table_row, random_question);
    else
    	loop back to random_question generation
    end
    Can someone point me to an example please?

    Thanks guys!
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

    Comment

    • StealthFD
      Indigo Rose Customer
      • Apr 2004
      • 47

      #3
      Thanks Tigger... I was thinking along that line once too. But how did you avoid repeating questions?
      - Hey Captain, we hooked up Data to the internet... Wanna see what he can do?

      Comment

      • TJ_Tigger
        Indigo Rose Customer
        • Sep 2002
        • 3159

        #4
        oh yeah, I forgot to put put that in there. After extracting the random question from the temporary master table I would delete that index.

        Tigg
        TJ-Tigger
        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
        "Draco dormiens nunquam titillandus."
        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

        Comment

        Working...
        X