Problems with if statements in a loop

Godot Version

Question

Hello

I this is what i am traing to do

  1. generate a random number
  2. I make a loop that repeats exactly as often as the number
  3. in the loop I generate a random number between 1 and 0
  4. then 1 of 4 possibilities should happen all with the same probability
  5. to check which of the possibilities has happened something is printed

the problem i have is that only the first of the possibilities is printed

this is the cood i use:

func _ready():
var anzal = randi_range(5,16)
print(anzal)

for n in anzal: 
	var pfeil_richtung = randf() 
	
	if pfeil_richtung < 0.25:
		print("Links")
	
	elif pfeil_richtung <= 0.25 and pfeil_richtung > 0.50:
		print("Rechts")
	
	elif pfeil_richtung <= 0.50 and pfeil_richtung > 0.75:
		print("oben")
	
	elif pfeil_richtung <= 0.75 and pfeil_richtung >= 1:
		print("Unten")

This condition (and the following ones) is never met. Change it to:

elif pfeil_richtung >= 0.25 and pfeil_richtung < 0.50:

2 Likes

Thank you very much

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.