daividpace's Recent Forum Activity

  • Finally. I narrowed the cause (or rather the solution, because I'm not entirely sure what the causereally is). The secret was in this line that mrcgkh used while debugging:

    For some reason "printing" all the values of the JSON object before removing the next random item prevents the item from repeating. I'm not sure if the object restructures itself or something but the only thing I did (after testing a while every change in mrcgkh's version) was to add this Text and just "print" all the items there. That solved the problem. I noticed however, that everytime an item is removed from the JSON object, it "gets the value" of 0 and it's position on the array is now last.

    Another thing I realized while debugging was that the problem ocurred always that de next random index was equal to the previous selected random index.

    I would really aprettiate it if someone that understands why this happens could explain, because I'll be using Construct a lot this year and I could really use a deep understanding in this type of things in the engine.

    Thanks a lot guys!

    Special thanks to mrcgkh for contributing :)

    For anyone interested in testing the "solution" of the original sample project, here is a copy with that simple modification mentioned above, the only difference is a Text object with id="fix" that prints the values of the JSON (feels more like a hack): dropbox.com/s/y2221fnwznf1d95/RandomJSON%28fixed%29.c3p

    David.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • mrcgkh Yess! you're right. It appears to be working in that way. Ok, I'll try to implement it that way on my main project :) thank you very much!

    (by the way, is there a way sort of to mark this thread as "solved" or to assign a correct answer like in Stack Overflow?)

    Thanks!

    David.

  • mrcgkh Yeah.. I think so too. I feel like the code should actually work that way. I will try with Arrays though when I am able to parse the data into an Array, and see what happens.

    Thanks!

    David.

  • oosyrag Awesome! Thanks, I'll be researching in the meantime If I come up with something I'll let you know.

    Thanks again.

    David.

  • Thanks oosyrag for your reply. I tried storing the AJAX fetched data into an Array as you suggested, however something's not right. I was reading that in order to cast a JSON into an Array it needs to have an specific structure, is this true?

    Initially, when I was passing the AJAX fetched data to the JSON object and updated the Text object to show it using:

    The result "printed" in the Text object looked like this:

    I tried storing the AJAX fetched data into an Array by doing this:

    But the result looks like this:

    Is there a way to load the original JSON without modifying it's structure? and first of all, was my procedure correct? (how I loaded the AJAX data into the Array object I mean).

    Thanks for your time.

    David.

  • I'm trying to implement a trivia game that should consist of a question and 3 different answers. This information would be extracted from a JSON. I currently know how to load JSON data into the project through AJAX and to select random sets of Q&A's. The part I'm having trouble with is to remove sets of Q&A that were already answered.

    In the sample project that I'm uploading there's a blue button to simulates when a new set is loaded into the view, a Text object that displays the JSON data and updates everytime a new set is loaded (and supposedly removed) and a "console" (another Text object) that displays the index that was selected randomly by the program.

    Sometimes it works as expected, but sometimes not. And I haven't been able to detect when is that it fails.

    I would appretiate if someone could take a look at the project. Thanks in advance.

    Project: dropbox.com/s/g3rga3yh4pyiue0/RandomJSON.c3p

    David.

    Tagged:

daividpace's avatar

daividpace

Member since 18 Jan, 2021

None one is following daividpace yet!

Trophy Case

  • 3-Year Club
  • Email Verified

Progress

4/44
How to earn trophies