Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2004
    Posts
    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)

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    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.

  3. #3
    Join Date
    Nov 2004
    Posts
    2
    Thanks very much

  4. #4
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    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

  5. #5
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    Nice one Tigg!

  6. #6
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Quote Originally Posted by Corey
    Nice one Tigg!
    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

Similar Threads

  1. String.right stealing my zeros....
    By patrick6 in forum AutoPlay Media Studio 5.0
    Replies: 8
    Last Post: 10-31-2004, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts