How do I set JSON item 'true'

0 favourites
  • 6 posts
From the Asset Store
Math questions appear quickly on the page, so you must respond quickly to get points!
  • Hi Guys,

    I am currently creating a quiz game and I want the questions to be pulled out of the JSON document automatically. Using the Load-JSON plugin I was able to load the text up no problems but i was wondering if anyone knew how to tell the JSON which of the answers are correct?

    Below is my currently JSON text with the first set of numbers being the question number, then the question (Q1) and then the set of answers.

    {
    	"1": ["Q1", "1", "2", "3", "4"],
    	"2": ["Q2", "1", "2", "3", "4"],
    	"3": ["Q3", "1", "2", "3", "4"],
    	"4": ["Q4", "1", "2", "3", "4"]
    }
    [/code:19nxcgzt]
    
    From reading forums and guides, it seems that I am suppose to add ':true' after the correct answer but everytime I try that I just get an 'Nothing Found' Message.
    
    Your help will be greatly appreciated as I am only starting to learn about ARRAY & JSON
  • If you have a static number of answers (and as I can see in your example there are always 4) then you can simply add 6th parameter which will determine which answer is correct.

  • then compare the correct_index value (the #5 index slot in your array; or 6th slot) to the player's choice, like:

    if player_choice == JSON.array.At(5)

    then Set Text: "Correct!"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks guys! I will give this a shot

  • ai4ns ..you don't need another cell...

    just set your array like this:

    so

    {
    	"1": ["Q1", "1", "2", "3", "4"],....."1"=True
    	"2": ["Q2", "1", "2", "3", "4"],....."1"=True
    	"3": ["Q3", "1", "2", "3", "4"],....."1"=True
    	"4": ["Q4", "1", "2", "3", "4"]......"1"=True
    }
    [/code:3f9da2l8]
    ..and then randomize  Answers position....
    
    like this:
    [url=https://app.box.com/s/kkumyils1frlc8gel6n0tcau0je68hhl]example.capx[/url]
    
    [img="http://i61.tinypic.com/2v998qo.png"]
  • Thanks korbaach really helpful! Thanks soo much!! I will give this a shot tomorrow when I jump back on this!

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