How do I set JSON item 'true'

Get help using Construct 2

Post » Mon Aug 31, 2015 2:24 pm

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.
Code: Select all
{
   "1": ["Q1", "1", "2", "3", "4"],
   "2": ["Q2", "1", "2", "3", "4"],
   "3": ["Q3", "1", "2", "3", "4"],
   "4": ["Q4", "1", "2", "3", "4"]
}


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
B
4
Posts: 8
Reputation: 214

Post » Mon Aug 31, 2015 3:03 pm

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.
ImageImageImage
B
27
S
16
G
80
Posts: 1,021
Reputation: 44,761

Post » Tue Sep 01, 2015 10:34 pm

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!"
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,418
Reputation: 4,830

Post » Fri Sep 04, 2015 2:21 am

Thanks guys! I will give this a shot :)
B
4
Posts: 8
Reputation: 214

Post » Fri Sep 04, 2015 6:25 pm

@ai4ns ..you don't need another cell...
just set your array like this:

Image

so

Code: Select all
{
   "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
}

..and then randomize Answers position....

like this:
example.capx


Image
B
66
S
24
G
7
Posts: 1,515
Reputation: 11,041

Post » Mon Sep 14, 2015 2:43 pm

Thanks @korbaach really helpful! Thanks soo much!! I will give this a shot tomorrow when I jump back on this!
B
4
Posts: 8
Reputation: 214


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests