Error with randomizing pitch scale! help pls!

Godot Version

4.2.1 stable

Question

Hi! So I cant seem to figure out why I keep getting this error message in the debugger whenever the sound plays. It only has to do with the pitch scale as when I take it off it is completely fine. Below is the code, and below that is the error message!

func _process(delta: float) → void:
if Input.is_action_just_pressed(“Knock”):
var pitch = rng.randi_range(0.5, 2.5)
%KnockingSound.play()
%KnockingSound.set_pitch_scale(pitch)

error message:
E 0:00:05:0013 main.gd:45 @ _process(): Condition “!(p_pitch_scale > 0.0)” is true.
<C++ Source> scene/2d/audio_stream_player_2d.cpp:243 @ set_pitch_scale()
main.gd:45 @ _process()

thanks!

randi_range() is for integer numbers, and you use floats

int randi_range ( int from, int to )

Returns a pseudo-random 32-bit signed integer between from and to (inclusive).


randf_range() is for floats

float randf_range ( float from, float to )

Returns a pseudo-random float between from and to (inclusive).

2 Likes

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