Placeholder zeros

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • SB3606
    Forum Member
    • Nov 2004
    • 2

    Placeholder zeros

    Is there a way to have a variable as 01 rather than 1? I have it set to that, but whenever I do "unitnum = unitnum + 01;" it just gets rid of the zero. I need these for writing strings of values for a Play-by-Email game I'm making. (using AMS to make the army builder)
  • Worm
    Indigo Rose Customer
    • Jul 2002
    • 3971

    #2
    You could cheat and do something like this.

    if String.Length(unitnum) == 1 then
    unitnum = "0"..unitnum
    end

    The issue is that unitnum is a nurmeric variable, so the leading 0 is dropped. Once you combine the string variable "0" with it, it becomes a string, and the 0 leads as you want.

    Comment

    • SB3606
      Forum Member
      • Nov 2004
      • 2

      #3
      Thanks very much :lol

      Comment

      • TJ_Tigger
        Indigo Rose Customer
        • Sep 2002
        • 3159

        #4
        LUA has a string.format (all lowercase) that can do this as well.

        Code:
        num = 1
        num = string.format("%02.f", num)
        Label.SetText("Label1", num);
        The % is an escape sequence, the zero is the padding, two for the number of characters and a decimal place holder followed by f for float.
        TJ-Tigger
        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
        "Draco dormiens nunquam titillandus."
        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

        Comment

        • Corey
          Indigo Rose Staff Alumni
          • Aug 2002
          • 9745

          #5
          Nice one Tigg! :yes

          Comment

          • TJ_Tigger
            Indigo Rose Customer
            • Sep 2002
            • 3159

            #6
            Originally posted by Corey
            Nice one Tigg! :yes
            Thanks trying to lear a little from the Lua-users.org site
            TJ-Tigger
            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
            "Draco dormiens nunquam titillandus."
            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

            Comment

            Working...
            X