Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CodeShaastra |
I am new to Godot. I have a json file with several questions and want to randomly pick questions from that how can i access them.
"1":
{
"image": "res://Images/Stills/1.jpg",
"question": "NIL",
"choices": {"a":"A Wednesday!","b":"Sunday","c":"Aiyaary","d":"shoot on sight"},
"hint": "Naseeruddin shah plays a common man determined to punish millitants on a particular day.",
"answer": "a"
},
"2":
{
"image": "res://Images/Stills/2.jpg",
"question": "NIL",
"choices": {"a":"Golmaal","b":"Singham","c":"Shivaay","d":"Omkara"},
"hint": "Ajay Devgn is a mountaineer who makes a living by providing treks and climbing expeditions to tourists.",
"answer": "c"
},
Here is my code
var file = File.new()
file.open("res://QuizData/BollyQuestions.json",File.READ)
var json_str = file.get_as_text()
var game_data = {}
game_data.parse_json(json_str)
var randQuestion =get_random_number()
var image = load(game_data.randQuestion.image)
func get_random_number():
randomize()
return randi()%3
Basically randQuestion should randomly generate “1”,“2” and so on tried str(randQuestion) didn’t work.
randi()%3
will also return 0
.
jandrewlong | 2018-05-08 14:25