How do I load info from a txt file (got some issues)

1 favourites
  • 6 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • I'm tryna read info from a .txt file (I've attached pics of my code below):

    here Ajax completed

    here Loadin' info

    My txt file's got a structure like this:

    Here'sWrittenAQuestion;

    Answer1;

    Answer2;

    Answer3;

    Answer4;

    RightAnswer;

    |

    and so on ('|' - it separates questions, ';' - it separates answers)

    (I'm working on a trivia game)

    So this method works really great with question from 0 through 9 but when it other nums starts like 11, 12, 13 (double figures) it doesn't work. I've got none.

    Could you please help me with this.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Instead of fixed screenshots, consider sending the actual project (.c3p file) you are using.

    This will be easier to investigate and answer.

    Why are you using a for loop in event 9 ? You are not making any usage of the "loopindex" value.

    Are you sure your array's size is correctly set and ready to hold more values than the default 10 ?

  • yes here u go

    the link for the project on my Dropbox: dropbox.com/s/spalj8chmyd85to/Trivia.capx

  • I've figured it that the problem appears when variable 'number_of_questions' is more than 9 (10 and greater) but I really dunno what's exactly going wrong.

    Maybe something going wrong with array or random or with reading file. Could you plz figure that out.

    I can do whatever u want to fix the issue - just have a look at my file - I've attached the link to the Dropbox above.

  • As mentioned in my previous answer the array size by default is 10.

    It means, by default and without further action on your part, it can only contain up to 10 elements.

    So when you try to put question 11 in the array, there is simply no room for it.

    The fix is very simple, in LoadQuestionsFromString, add a blank sub-event before the "each question" loop.

    Have this blank sub-event have the action QuestionsArray: Set size to (number_of_questions, 1, 1) and your array will fit the actual number of questions you are trying to put in.

  • Thank you so much! It really helped me. Thanks.

    As mentioned in my previous answer the array size by default is 10.

    It means, by default and without further action on your part, it can only contain up to 10 elements.

    So when you try to put question 11 in the array, there is simply no room for it.

    The fix is very simple, in LoadQuestionsFromString, add a blank sub-event before the "each question" loop.

    Have this blank sub-event have the action QuestionsArray: Set size to (number_of_questions, 1, 1) and your array will fit the actual number of questions you are trying to put in.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)