Advertisement
Guest User

quiz script

a guest
Jun 5th, 2023
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.81 KB | Gaming | 0 0
  1. extends Node
  2.  
  3. var index = -1
  4.  
  5. func _ready():
  6.     # make all questions answers invisible
  7.     for question in Node.get_children():
  8.       question.visible = false
  9.       question.get_child(0).visible = false
  10.  
  11.     show_next_question()
  12.  
  13. func show_next_question():
  14.     if index + 1 < Node.get_child_count():
  15.         # increase the index by one and make the question
  16.         index += 1
  17.         Node.get_child(index).visible = true
  18.     else:
  19.         print("no more questions")
  20.  
  21. func _on_question_pressed():
  22.     # Hide the current question and show its answer.
  23.     var question = Node.get_child(index)
  24.     question.self_modulate = Color(1.0, 1.0, 1.0, 0.0)
  25.     question.get_child(0).visible = true
  26.  
  27.     # Create a 5-second timer to display the new question
  28.     var tween = create_tween()
  29.     tween.tween_interval(5)
  30.     tween.tween_callback(question.set_visible.bind(false))
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement