dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: array's and int's problem

Hybrid View

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    47

    Question array's and int's problem

    i'm making a quiz in flash that loads random images with questions (50 in total)
    and i want to check if someone answers right (obvious).....

    i'm using this script to check if you answer correctly:
    PHP Code:
    if (answers[randomnumber].selected)
        {
            
    score++;
            } 
    the answers is an Array with the correct answers.
    the randomnumber is this:
    PHP Code:
    var high:int 50;
    var 
    low:int 1;

    var 
    randomnumber:int = (Math.floor(Math.random()*(1+high-low))+low
    the .selected is because it uses radio buttons.
    but it doesn't work!

    for testing i modded it so that you get the same question every time and i answered the same every time (correctly) but it says that i don't have everything right?!

    can someone help me with this problem?? thank is advance

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I suspect that you put something other than a radio button in the answers array.
    Post the code where you populate answers.

    Also, do not use apostrophes to make a word plural. "Arrays", and "ints", not "array's" and "int's".

    http://www.angryflower.com/bobsqu.gif

  3. #3
    Member
    Join Date
    Jan 2011
    Posts
    47
    sorry for the bad english ^^

    and here is the answers array:

    PHP Code:
    var answers:Array = [stelling_2,stelling_3,stelling_1,stelling_2,stelling_1,stelling_2,stelling_2,stelling_2,stelling_3,stelling_3,stelling_1,stelling_1,stelling_3,stelling_2,stelling_1,stelling_1,stelling_3,stelling_2,stelling_1,stelling_1,stelling_2,stelling_3,stelling_3,stelling_1,stelling_3,stelling_2,stelling_1,stelling_2,stelling_2,stelling_2,stelling_1,stelling_3,stelling_2,stelling_1,stelling_3,stelling_1,stelling_3,stelling_3,stelling_2,stelling_3,stelling_1,stelling_2,stelling_3,stelling_1,stelling_1,stelling_3,stelling_1,stelling_1,stelling_2,stelling_2]; 
    stelling_1
    stelling_2
    stelling_3
    are the radio buttons

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, it looks like you actually put the radio buttons in the array, so my first guess wasn't right.

    You do know that arrays start at 0, right, so the first answer is answers[0] not answers[1]?

  5. #5
    Member
    Join Date
    Jan 2011
    Posts
    47
    yea i know but maybe i overlooked it in my script thx for pointing it out gonna check.

  6. #6
    Member
    Join Date
    Jan 2011
    Posts
    47
    thanks i was stupid -_-

    instead of:
    PHP Code:
    if (answers[randomnumber 1].selected
    i used

    PHP Code:
    if (answers[randomnumber].selected
    so if you get question number 49 it would check the answer for question number 48.

    thanks again for your help i already user the 0 counting for the rest of the script

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center