|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sun Nov 05, 2006 6:19 am
[1.13] database variable stripping zeros |
testvar={005|010}
#SH %item(@testvar,1)
Returns:
005
testbdv=%null
#ADDKEY testdbv key1 005
#ADDKEY testdbv key2 010
#SH %db(@testdbv,key1)
Returns:
5
I need it to return 005, because:
when I use %sort:
1,2,3,4,5,6,7,8,9,10,11,12
gets sorted to
1,10,11,12,2,3,4,5,6,7,8,9
which is no good to me, which is why I wish to use 005, 010, 100, etc (forces the %sort to put the smallest number first)
Is this a bug, or is it intended (in which case there are other options/workarounds)? |
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sun Nov 05, 2006 6:30 am |
It may not be clear..
herbaffs={010_paralysis|005_stupidity|070_recklessness}
herbaffs=%sort(@herbaffs)
#EXEC %item(@herbaffs,1)
herb_cure_priorities={paralysis=010|stupidity=005|recklessness=070}
I'd like to use something like the following alias, to create the @herbaffs stringlist from a script.
#AL addherbaff {#addi herbaffs {%db(@herb_cure_priorities,%1)_%1}}
but at the moment it creates {5_stupidity|10_paralysis|70_recklessness}, which doesn't sort the same way as if the zeros at the beginning are preserved. I can work around this by simulating a database variable with two stringlists, but I don't know if this is a bug or intended behaviour. If its a bug I'll wait for the fix, if its not a bug then I'll go the more complex solution. |
|
|
|
The Raven Magician
Joined: 13 Oct 2000 Posts: 463
|
Posted: Mon Nov 06, 2006 5:14 pm |
Hmm. I don't have CMUD here, but have you tried:
#ADDKEY testdbv key1 "005"
That might force it to interperet as a string, rather than a number. |
|
|
|
The Raven Magician
Joined: 13 Oct 2000 Posts: 463
|
Posted: Mon Nov 06, 2006 5:19 pm |
A workaround, that could tide you over until you find a proper fix, is to use letters rather than digits. Priorities could range from AA to ZZ rather than 00 to 99. You could also start the priorities at 1 rather than 0... 100 could be the lowest priority.
I agree it could be better to have a proper fix, but barring that (since *Mud processing is notoriously difficult to control) either of these workarounds should allow your scripts to work just fine in the interim. |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Mon Nov 06, 2006 6:14 pm |
I think The Raven is correct. You'll probably just want to use double quotes around it, as CMUD now is designed to properly type values instead of guessing based on context. You see the priorities as numeric, but really you're sorting strings and not numbers.
|
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Mon Nov 06, 2006 6:21 pm |
I'd have thought it should guess 010 as a string, but 10 as a number... it does sound like a bug though that it treats them as numbers in variables and strings in keys
|
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Tue Nov 07, 2006 10:14 am |
I should have mentioned this:
#addkey test key1 005
#addkey test key2 013
#showdb @test
key1: 003
key2: 013
#sh %db(@test,key1)
3
Using double quotes:
#addkey test key1 "005"
#sh %db(@test,"key1")
doesn't change anything. Is this a bug do you think?
I'd prefer to use numbers because while I can use letters easily enough, the plan is to create a backbone curing system that is simple for unexperienced zmudders/cmudders to adjust for themselves. I'm attempting to create a "CaledIreMudScript" in CMUD. Not to create an autocure that will make everyone that uses it shit-hot, but to create a backbone for them to fill up with stuff they learn about fighting in the mud, without the need to match that knowledge with coding knowledge.
Letters will work for now though. I daydreamed this up today at work:
#FUNC prioHcure {%case(%len(%db(@hPrioNumList,%1)),%concat(00,%db(@hPrioNumList,%1),%concat(0,%db(@hPrioNumList,%1),_,%1),%concat(%db(@hPrioNumList,%1),_,%1))}
(Wrote that off top of head now. Its probably "syntaxically" wrong but the idea should be clear.)
#ADDITEM herbaffs @prioHcure(stupidity)
But I think that its probably not worth bothering with and just using the letters. In honesty using letters never occurred to me |
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Nov 07, 2006 8:36 pm |
I'll see if I can improve the parser to treat something with leading zeros as a string, but it would really be better for you to use quotes so that there is no confusion possible in the script. It will help avoid other obscure errors in your script down the line.
If it's not working correctly with the quotes, then that's a bug and I'll add it to the list. Commands such as #ADDKEY, #ADDITEM, etc are not as well tested when dealing with variables types as the #VAR command is. |
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Tue Nov 07, 2006 9:32 pm |
Its not working correctly with the quotes. I'll bug it formally later on today.
|
|
_________________ Athlon 64 3200+
Win XP Pro x64 |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Wed Nov 08, 2006 12:10 am |
The problem there is with the %db function returning it as 5 and not "005" as it should. If you use #SHOWDB @test, the value is correct.
|
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|