Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Leading zeros wanted.
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Tue 15 May 2007 03:10 AM (UTC) |
Message
| I'm trying to have a script display time in a format like 2m:05s in a script. Unfortunately, I can't find a nice way to add a zero in front of the seconds if it is less than 10 seconds without a separate if statement. Is there a string format option better than string.format( "%2dm:%2d", min, sec ) for what I'm trying to do, or should I give up and put an if statement in and just make a string out of it? |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Tue 15 May 2007 03:30 AM (UTC) Amended on Tue 15 May 2007 03:31 AM (UTC) by David Haley
|
Message
| [david@thebalrog:~]$ cat test.lua
#!/usr/bin/lua
str = string.format("%02d %02d %03d", 0, 1, 2)
print(str)
[david@thebalrog:~]$ lua test.lua
00 01 002
That is what you want, no? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #2 on Tue 15 May 2007 03:34 AM (UTC) |
Message
| Yes, precisely what I want to do. Thanks... been a while since I've needed to use those C formats. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #3 on Tue 15 May 2007 09:42 PM (UTC) Amended on Tue 15 May 2007 09:45 PM (UTC) by Shaun Biggs
|
Message
| I'll just continue with using this to ask for string format help... Can anyone tell me what's wrong with this?
<alias
match="chancap:list"
send_to="12"
regexp="y"
enabled="y"
>
<send>for i,v in pairs( channels ) do
ColourNote( "white", "black", string.format( "%10s", tostring(i) ),
"lime", "black", " :"..v )
end
</send>
</alias>
currently this spits out:
0s :true
0s :true
0s :true
if I get rid of the string.format bit, and just have i, then it shows the correct keys and values, but it's all messy looking.
Oh, and the value of channels = { ["clan"] = "true", ["ftalk"] = "true", ["spouse"] = "true" } |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #4 on Wed 16 May 2007 12:20 AM (UTC) |
Message
| I don't get this behavior:
[dhaley@visionary:~]$ cat test.lua
channels = { ["clan"] = "true", ["ftalk"] = "true", ["spouse"] = "true" }
for i,v in pairs(channels) do
print(string.format("%10s", tostring(i)), " :" .. v)
end
[dhaley@visionary:~]$ lua test.lua
spouse :true
ftalk :true
clan :true
The key/val pairs it prints out are exactly the ones in the table. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #5 on Wed 16 May 2007 12:21 AM (UTC) |
Message
| Oh. Is it possible that MUSHclient is doing a preprocessing step and translating %1 to the value of the first match, which is empty, and so the string.format string is actually just "0s" because the %1 gets removed? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #6 on Wed 16 May 2007 02:08 AM (UTC) |
Message
| Yep, that did it. I sent everything to a separate script, and it seems to be working fine now. I'm starting to think I should pay some sort of attention while scripting from now on. That explains why copying the syntax from one function to the script in the alias didn't act the same at all. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
28,461 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top