|
Jah Wanderer
Joined: 11 Oct 2000 Posts: 52 Location: Sweden
|
Posted: Mon Jul 07, 2003 4:18 am
Chop a variable/list |
Is there a way to "chop" a variable? For instance i would like something like
#var list {1 a|2 b|3 c}
%getfirst(@list)
and then it would be 1|2|3 so i can trigger it on 2 instead of 2 a. |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Mon Jul 07, 2003 4:58 am |
#var choplist %replace(@list," ","|")
choplist = 1|a|2|b|3|c
or
#alias getfirst {#var choplist %item(@list,%i);#var choplist %replace(@choplist," ","|");#var choplist %item(@choplist,1);#show @choplist}
or
#trigger {you get some ({@list})} {#var choplist %replace("%1"," ","|");get %item(@choplist,1)}
but if you want this:
#trigger {you get some {@list}}
where list = 1 a|2 b|3 c
and you want it to do this instead:
list = 1|2|3
then no I don't think you can. |
|
|
|
Jah Wanderer
Joined: 11 Oct 2000 Posts: 52 Location: Sweden
|
Posted: Mon Jul 07, 2003 5:33 am |
*ponder*
So there is no way to do like :
#forall @listan {
#var listan %expandlist( @listan, ",")
#var adding %max( @listan)
#var list2 %additem( @adding, @list2)
#var listan %replace( @listan, ",", "|")
#delitem listan @adding
}
#var list2 %dups( @list2)
It seams to work fine exept that it only reacts on first number in a list... Hmm...
@Listan is something like = 41 e|1 b|2000 c |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Mon Jul 07, 2003 11:07 am |
Use a record variable instead of a list. Look at the commands #ADDKEY, #DELKEY, #LOOPDB; and functions %db and %expanddb. Also triggers can use record variables the same way as lists (read Pattern Matching).
|
|
|
|
Jah Wanderer
Joined: 11 Oct 2000 Posts: 52 Location: Sweden
|
Posted: Mon Jul 07, 2003 4:06 pm |
Woho. It's a whole new world. Thanks vijilante.. Now i can have some more fun and stop crying ;)
EDIT : ok more crying :P
Umm how do i do this correctly? :)
#loopdb @db1 {#show %sort(%val,1)}
Nm... (http://www.zuggsoft.com/forum/topic.asp?TOPIC_ID=10049&SearchTerms=loopdb) |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Mon Jul 07, 2003 11:44 pm |
%sort() doesn't do numbers, so your list will end up going along the lines of 1|10|100|2|20|200|etc. You will have to manually sort the list. If I remember my sort logic correctly, it goes something like this:
Code: |
outer loop starts, grabs first element in list
inner loop starts, compares %i to %j
if %i is greater than %j
switch %i with %j
iterate inner loop until %j = last element
iterate outer loop until %i = last element
|
The above logic should work equally well in reverse.
Two nested #while commands should do the trick, though in your case you'll also need to extract the numeric portion from each list element.
#alias SortNumbers {#variable CounterI %numitems(%1)
#while (@CounterI) {do numeric extraction work for @CounterI item here;#math CounterJ (@CounterI-1);#while (@CounterJ) {do numeric extraction for @CounterJ item here;#if (Numeric portion of @CounterI item < Numeric portion of @CounterJ item) {do switch stuff} {#NOOP};#ADD CounterJ -1};#ADD CounterI -1}}
there's no easy way to switch two elements in a list that I know of, so you'll have to save one value (position 1) to a temporary value (position 3), replace the old saved value with the unsaved one (position 2), and then overwrite the unsaved value with the temporary variable. |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Tue Jul 08, 2003 1:50 pm |
This question about putting numbers in order has intreged me, so I will indever to research the problem and maybe come up with something for you. I am currently working on a script that requires thing to be in numerical order, so it will benifit us both.
write soon. |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Tue Jul 08, 2003 3:56 pm |
It's not so hard. The link Jah provided already has the solution. Just use %repeat to pad the beginning of all the numbers in the list with 0's until they are all the same length. Example:
#LOOP 1,%numitems(@list) {#VAR list %replaceitem(%concat(%repeat("0", 10 - %len(%item(@list, %i))), %item(@list, %i)), %i, @list)}
Then, use %sort on it to sort the numbers and use %eval to remove the extra 0's:
#VAR list %sort(@list)
#LOOP 1,%numitems(@list) {#VAR list %replaceitem(%eval(%item(@list, %i)), %i, @list)}
If numbers longer than 10 digits are to be sorted, the only thing that needs to be changed is the 10 in the %repeat to the amount of digits desired. |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Sun Jul 13, 2003 8:09 pm |
UNfortunatly I did not check back here or I would have seen Kjata post and saved myself alot of time and effort but here is what i came up with. (i usually collor these things but this is pretty big so I will forgo that)
#CLASS {Numerical}
#ALIAS no {#var ones "";#var tens "";#var hundreds "";#var thousands "";#var tentho "";#var huntho "";#var millians "";#var tenmil "";#var hunmil "";#var billions "";#var recount "";#var new %sort(@new);#var countlist %numitems(@new);#loop 1,@countlist {#if %len(%item(@new,%i))=1 {#addi ones %item(@new,%i)};#if %len(%item(@new,%i))=2 {#addi tens %item(@new,%i)};#if %len(%item(@new,%i))=3 {#addi hundreds %item(@new,%i)};#if %len(%item(@new,%i))=4 {#addi thousands %item(@new,%i)};#if %len(%item(@new,%i))=5 {#addi tentho %item(@new,%i)};#if %len(%item(@new,%i))=6 {#addi huntho %item(@new,%i)};#if %len(%item(@new,%i))=7 {#addi millians %item(@new,%i)};#if %len(%item(@new,%i))=8 {#addi tenmil %item(@new,%i)};#if %len(%item(@new,%i))=9 {#addi hunmil %item(@new,%i)};#if %len(%item(@new,%i))=10 {#addi billions %item(@new,%i)}};#if !%len(@ones)=0 {#addi recount @ones};#if !%len(@tens)=0 {#addi recount @tens};#if !%len(@hundreds)=0 {#addi recount @hundreds};#if !%len(@thousands)=0 {#addi recount @thousands};#if !%len(@tentho)=0 {#addi recount @tentho};#if !%len(@huntho)=0 {#addi recount @huntho};#if !%len(@millians)=0 {#addi recount @millians};#if !%len(@tenmil)=0 {#addi recount @tenmil};#if !%len(@hunmil)=0 {#addi recount @hunmil};#if !%len(@billions)=0 {#addi recount @billions};#echo %replace(%replace(@recount,")",""),"(","")}
#VAR new {1|12|2|3|30|54|55}
#VAR countlist {7}
#VAR ones {1|2|3}
#VAR tens {12|30|54|55}
#VAR hundreds {}
#VAR thousands {}
#VAR tentho {}
#VAR huntho {}
#VAR millians {}
#VAR tenmil {}
#VAR hunmil {}
#VAR billions {}
#VAR recount {(1|2|3)|(12|30|54|55)}
#CLASS 0
Change the alias if you wish
and set variable @new with your numbers to put in order
I used echo to show me the results so you might have something else to do with this. have fun and remember with zmud all is posible |
|
|
|
|
|
|
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
|
|