Print a list item from array once at time with for cycle

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By damianus

Hello every one,

i have an array with 4 texts in it and i want to print each of them once at time with spacebar… i tryed to use for cycle but it seems to print all the array at once… thank you for your help

:bust_in_silhouette: Reply From: bloodsign
var index = 0
var array = ["text1", "text2", "text3", "text4"]

func _process(delta):
    if Input.is_action_just_pressed("ui_accept"):
          print(array[index]) #or $Label.text = String(array[index]) if you have a label
          index+=1
          if index == 4:
               index = 0 #reset to beginning