cybereality Thank you. I appreciate your help in explaining this for me.
I was wondering if I could trouble you again. I'm still struggling with the 'looping through arrays' logic for other parts of the quiz and converting to GD. The questions/answers are pulled from json files (they were xml) on my server. They were randomised. I found a godot quiz game on github that I'm using for reference but questions/answers in this game are not. It's not challenging to a player if they appear in the same order.
In GD I'm not understanding the difference between rand_range
, randi
and randf
.
This was the AS for shuffling questions...
//////////////// SHUFFLE ARRAY /////////////////////////
function ShuffleArray(input:Array)
{
for (var i:int = input.length-1; i >=0; i--) {
var randomIndex:int = Math.floor(Math.random()*(i+1));
var tempValue = input[randomIndex];
input[randomIndex] = input[i];
input[i] = tempValue;
}
}
//////////////PUSH NUMBER OF QUESTIONS INTO ARRAY//////////////////
function shuffleNumber(arr:Array, num:int, rand:String)
{
if (arr.length > 0) {
arr = [];
}
for (var i:int = 0; i <num; i++) {
arr[i] = i;
}
if (rand == "TRUE") {
ShuffleArray(arr);
}
}
Am more than certain that my GD conversion is totally wrong.
func ShuffleArray(input:Array):
#i >=0
#i = input.size()-1
for i in range():
i-=1
var randomIndex:int = randi()*(i+1)
var tempValue = input[randomIndex];
input[randomIndex] = input[i];
input[i] = tempValue;
func setupAnswerOptions(op:int):
for i in range(op):
i+=1
var mc = $Quizzes.get_node("button"+str(i));
mc.visible = true;
mc.id = i;
#checkAnswer();