In a current game project I wanted to show leading zeros when the scoreboard isn't filled up, I also wanted to crop it to a given number of spaces while still preserving the rightmost digit. I looked through the documents in AppGameKit Studio for a function for doing this and couldn't find one, so I brewed my own. I assume this should also work in AGK-2. I have also submitted this to the codebase.
do
if GetRawKeyReleased(27) then exit
print(PadStringZeros(1))
print(PadStringZeros(12))
print(PadStringZeros(123))
print(PadStringZeros(1234))
print(PadStringZeros(12345))
print(PadStringZeros(123456))
print(PadStringZeros(1234567))
print(PadStringZeros(12345678))
print(PadStringZeros(123456789))
sync()
loop
end
function PadStringZeros(num as integer)
local outString as string
local numToString as string
local padSpaces as string = "0000000" // Edit for preference of less or more reserved spaces.
numToString = str(num)
outString = mid(padSpaces, 1, len(padSpaces) - len(numToString)) + numToString
if len(numToString) > len(padSpaces)
outString = mid(numToString, len(numToString) - len(padSpaces) + 1, len(padSpaces))
endif
endfunction outString