Replace digits with image labels

Hey ! i was wondering how to replace digits with image labels. here is an example
image

we replace the 5 with an image label of an image with a five on it, how would i do that? is it even possible?

1 Like

Sure, it’s possible. Just iterate through every digit of the number (there are multiple ways to do this) and replace each digit with its own separate ImageLabel. A horizontal UIListLayout could help with this.

i’ve been wanting to do that, but how do iterate though each digit?

Two ways come to mind. You can either:

  • mod 10 a number to get its last digit and then floor divide it by 10, giving you every digit from last to first (you will have to reverse the order of digits)
  • string manipulation, converting the number to a string using tostring and then using string.gmatch(str, ".")

Either works.

umm sorry i didnt understood that, im kind of a beginner in coding, could you make that simplier?

Read up on strings so you can have a greater understanding.

Here’s a basic implementation of what you’ll want:

-- This is your number
local number = 123456

for v in string.gmatch(tostring(number), ".") do
  -- This will be the nth digit of your number, from the first digit to the last
  print(v)
end

Output:

-- 1
-- 2
-- 3
-- 4
-- 5
-- 6

The gmatch function is an iterator function that returns a specific part of a string every time it is called. In other words, it looks for a certain pattern within a string each time it is called. The "." capture simply matches the next character, which results in every character from start to finish.

1 Like

thanks for the help, im gonna go learn more about strings

1 Like

Sorry to bother you again but i cant figure out how to make it. Its very complex