How to loop for a number of times?

Question

I wanna create a Loop for this function, this function gets called onetime form the animation_player´.
I heard while loops should be avoided if possible so I’m searching for alternatives

If you have another idea how to offset.y until is reach his max offset, please let me know.

Or is there a way to call a function several times in the animation player?

With this code it get offset onetime (2pixels) and that’s it.
And i don’t can fix this with a camera Limit

func camera_offsetting(delta):
	if camera_2d.position.y > -65:
		if camera_2d.offset.y <= -32:
			return
		else:
			camera_2d.offset.y = -2 * delta

You could create an animation track for the camera 2d offset value, or use a tween if you do not know the starting or end value.

Here’s a small code example on using a tween, you will have to plug in your own end_pos. This should be called once for the duration of the tween.

var end_pos: float
var duration: float

func camera_offsetting(delta):
	if camera_2d.position.y > -65 and camera_2d.offset.y > -32:
		var tween := camera_2d.create_tween()
		tween.tween_property(camera_2d, "offset:y", end_pos, duration)

I think

for I in range(x,y,z):

also works in gdscript. X is the starting, would suggest 0, y is the amount of times you want to repeat it, would be amount of time you want to repeat-1(if x is 0) z would be the steps you want to do it in, though you wouldn’t need that for this functionality