Local variables in repeat events

This would be really useful, you see.
It’d save me from having to make a separate variable for repeatIndex(), or some other very niche but useful variables in certain situations.


In this screenshot I attempt to create a local variable for RepeatIndex, as I’m already using it a bit to the right, but it’s marked out, and I can’t?
This is one of the only times I have actually attempted to use local variables, and probably one of the only reasons I would, so if this got fixed, I’d use it a lot more.

My work-around for that is to create an empty event with just the local variable declaration, and make the repeat a subevent off that.

BTW (going by the screenshot), as some advice - don’t use a beginning of scene within the repeat. Make the repeat a subevent of a “beginning of scene” event. Otherwise GDevelop iterates it every single game frame and does nothing.

1 Like

That is a nice work-around, but it would still be really convenient to just have the local variable be able to be in the repeat event.
Also thanks for the tip!

Yeah, agreed—your workaround definitely helps in the meantime, but having native support for defining local variables directly inside repeat events would be a huge quality-of-life improvement.

There are plenty of situations where you only need something like RepeatIndex() temporarily, and creating a whole new event just to declare it feels a bit clunky. It’d make complex logic more readable too, especially when nesting repeats or mixing in other calculations.

1 Like

What I want is a for next type event with a variable.

For variable = number to number step number

It could either create the variable as a local variable or use an existing variable like for each child event. Although, I would prefer the local variable approach.

2 Likes