Get value from JSon double array using multiple global variables

I have a json setup like the below. I import and convert that json file into a variable called “questions”. I have two more global variables: questionNumber & randomQuestionSelection (the second of which is randomized to be 0 or 1).

The problem is I can easily access the text of my questions using:
GlobalVariableString(questions[GlobalVariable(questionNumber)].0.question)

But I want to use something like this, but its just not working:
GlobalVariableString(questions[GlobalVariable(questionNumber)].GlobalVariable(randomQuestionSelection).question)

Any suggestion?

my json:

[
    [
        {
            "question":"This is the first question and the first option?",
            "feedback":"This is the feedback for the first question and first option.",
            "answerA":{
                "text":"answer A text",
                "correct":true
            },
            "answerB":{
                "text":"answer B text",
                "correct":false
            },
            "answerC":{
                "text":"answer C text",
                "correct":false
            },
            "answerD":{
                "text":"answer D text",
                "correct":false
            }
        },
        {
            "question":"The is the first question and the SECOND option.",
            "feedback":"Feedback for first question and second option",
            "answerA":{
                "text":"answer A text",
                "correct":true
            },
            "answerB":{
                "text":"answer B text",
                "correct":false
            },
            "answerC":{
                "text":"answer C text",
                "correct":false
            },
            "answerD":{
                "text":"answer D text",
                "correct":false
            }
        }
    ],
    [
        {
            "question":"This is the second question and the first option",
            "feedback":"This is the feedback for the second question and first option.",
            "answerA":{
                "text":"answer A text",
                "correct":true
            },
            "answerB":{
                "text":"answer B text",
                "correct":false
            },
            "answerC":{
                "text":"answer C text",
                "correct":false
            },
            "answerD":{
                "text":"answer D text",
                "correct":false
            }
        },
        {
            "question":"This is the second question and SECOND option.",
            "feedback":"This is the feedback for the second question and second option",
            "answerA":{
                "text":"answer A text",
                "correct":false
            },
            "answerB":{
                "text":"answer B text",
                "correct":false
            },
            "answerC":{
                "text":"answer C text",
                "correct":true
            },
            "answerD":{
                "text":"answer D text",
                "correct":false
            }
        }
    ]
]

You’re not using the correct expression to access dynamic variables.

.GlobalVariableblah won’t work.

Refer to the variable page of the wiki for more details: Variables [GDevelop wiki]

1 Like

Thank you! I never understood that part of the documentation until now. Also, thanks for always being so quick to respond!!

And for any future readers, the solution was:
GlobalVariableString(questions[GlobalVariable(questionNumber)][GlobalVariable(randomQuestionSelection)][“question”])

2 Likes