RepeatCount = math.huge , will this blow up in my face?


#1

If I want to straight up loop a tween can I get a way with setting the RepeatCount in TweenInfo to math.huge - or is that dumber than I realise?

Cheers


#3

I set RepeatCount to 1e309 a few times, and it worked as expected.


#4

It should be fine to put a huge number there. I do this myself and haven’t run into issues yet.

EDIT: see zeuxcg’s reply below, -1 is neater.


#5

Setting repeat count to -1 also works in my experience. Seems to repeat forever.


#6

I think it works because they set the base number to 0 and then increment it until it reaches the other number(while num ~= yournum do). So yeah :slight_smile:


#7

Warning: This is not safe! Use RepeatCount = -1 instead!

RepeatCount is an integer; when you assign a Lua number value to an integer, you are relying on double->int casting rules that are not specified in C++. There are three possible options:

  • (sensible) Casting out of range floating point value to an integer clamps to INT_MIN or INT_MAX based on the original sign. I believe this is more or less how ARM works (so mobile). In this case you would get 2147483647.
  • (not very sensible) Casting out of range floating point value to an integer returns INT_MIN = -2147483648. This is how x86/x64 works (so desktop/consoles)
  • (insane) Casting out of range floating point value to an integer does… something stupid. Like returns 42. Or takes random 32 bits from the source value and leaves them as is.

RepeatCount is an integer, and negative values mean “repeat forever”. So in this specific case both actually observed behaviors are doing the same thing (on desktop you get a negative value and it repeats forever; on mobile you get 2^31 so it repeats essentially forever, although a 100ms tween with 2^31 repeat count will stop repeating in ~7 years), but you can not rely on it - one day we may port Roblox to an architecture that does something else and your code will break. Just use RepeatCount = -1.

(note: wiki currently doesn’t mention this but I’m told by @darthskrill that negative repeat counts are a feature so it should be safe to rely on; cc @UristMcSparks)


#8

Oh yeah that explanation is better.


#9

Great info, thank you.