|
rtatum Novice
Joined: 19 Sep 2004 Posts: 45 Location: Houston
|
Posted: Thu Oct 07, 2004 7:03 am
Help tweaking a script... |
Okay, nexela made a phone script that I regularly use, and it worked so well I figured I'd use it to model a new script I wrote on it, since the systems are fairly similar... now most of what this is is unimportant, but here's what it looks like now, and yes I know it's probably fairly messy and whatnot, but it works
#IF (%null( "%1")) {grid list}
#IF ("%1"="store") {
#ADDKEY coords {%lower( "%2")} {"%3" "%4"}
#SAY %proper( "%2") Stored
}
#IF ("%1"="delete") {
#DELKEY coords %lower( "%2")
#SAY %proper( "%2") Erased
}
#IF ("%1"="go") {
#IF (%iskey( @coords, %lower( "%2"))) {
~grid add %2 %db( @coords, %lower( "%2"))
~grid %2
~grid del %2
}
}
#IF ("%1"="list") {
#SHOW @empty
#SHOW ~#~ ~ ~ ~ Stored Coordinates ~ ~ ~ ~#
#LOOPDB @coords {#SAY %if( %mod( %iskey( @coords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#CR
}
#IF ("%1"="add") {
~grid add %2
~grid
#alarm +5 {
~grid del @addedcoords
#var addedcoord %null
}
}
I've bolded the section that I want moved... basically right now I type "grid go <destination>" and it executes several commands based on the destination... what I WANT to be able to do is type simply "grid <destination>" and have it do the same thing, but I've been having a bit of trouble, here's how I changed it, but when I try "grid <destination>" it does absolutely nothing at all, here's my attempt:
#IF (%iskey( @coords, %lower( "%2"))) {
~grid add %2 %db( @coords, %lower( "%2"))
~grid %2
~grid del %2
} {
#IF (%null( "%1")) {grid list}
#IF ("%1"="store") {
#ADDKEY coords {%lower( "%2")} {"%3" "%4"}
#SAY %proper( "%2") Stored
}
#IF ("%1"="delete") {
#DELKEY coords %lower( "%2")
#SAY %proper( "%2") Erased
}
#IF ("%1"="list") {
#SHOW @empty
#SHOW ~#~ ~ ~ ~ Stored Coordinates ~ ~ ~ ~#
#LOOPDB @coords {#SAY %if( %mod( %iskey( @coords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#CR
}
#IF ("%1"="add") {
~grid add %2
#alarm +5 {
~grid del @addedcoords
#var addedcoord %null
}
}
}
I also might add that if grid <command/destination> doesn't contain a valid command or destination, then it gives an error message
Another question... I'm trying to make a pattern to match lines like this:
Chinatown [-14400, 7300 ](Unavailable)
Chinatown would be one I want to store, so I'd put a (*) there, to account for any apostraphes that might be used in that word, and then a %s to match the variable spaces, but the numbers in the brackets are where it gets complicated... the first number is always always negative, so %n works there, but that's where the easy part ends... the second number is always positive, but the space between the comma and number isn't always there, and there are anywhere from no to 3 or 4 spaces after the second number, and I've not been able to make a pattern to match any situation for that... for example, another coordinate might look like:
Example1 [-1440 , 73003 ](Unavailable) |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Thu Oct 07, 2004 12:25 pm |
Top of head at a glance thought Change the refrences from %2 to %1
First if the first Word is Always one word you can use %x instead of *
If it is a FIXED amount of spaces (which it sounds like) use fixed-width pattern matching I believe starting and trailing spaces are trimmed when it is stored. If it is a random number of spaces then just use ,(*)~]
#TRIGGER {(*) ~[(%n),(&6) ~]} |
|
|
|
rtatum Novice
Joined: 19 Sep 2004 Posts: 45 Location: Houston
|
Posted: Thu Oct 07, 2004 4:28 pm |
Thanks again Nexela, it's always those simple things you tend to overlook, and thanks for the help on the pattern, it seems that it does trim leading and trailing spaces when you store it, which simplifies things a lot
|
|
|
|
rtatum Novice
Joined: 19 Sep 2004 Posts: 45 Location: Houston
|
Posted: Thu Oct 07, 2004 7:50 pm |
New problem popped up, I had it working, I don't think I changed anything but the "grid add" part of the alias stopped working, here's what it looks like now, the non-working part in bold
#IF (%iskey( @coords, %lower( "%1"))) {
~grid add %1 %db( @coords, %lower( "%1"))
~grid %1
~grid del %1
} {
#IF (%null( "%1")) {grid list}
#IF ("%1"="store") {
#ADDKEY coords {%lower( "%2")} {"%3" "%4"}
#SAY %proper( "%2") Stored
}
#IF ("%1"="delete") {
#DELKEY coords %lower( "%2")
#SAY %proper( "%2") Erased
}
#IF ("%1"="list") {
#SHOW @empty
#SHOW ~#~ ~ ~ ~ Stored Coordinates ~ ~ ~ ~#
#LOOPDB @coords {#SAY %if( %mod( %iskey( @coords, %lower( %key)), 2), %ansi( 7) , %ansi( 15))%proper( %key) %repeat( " ", %eval( 15-%len( %key)))%replace( %val, "|", %cr%repeat( " ", 14))%ansi( default)}
#CR
}
#IF ("%1"="add") {
~grid add %2
~grid
}
} |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Oct 08, 2004 11:18 pm |
Since you haven't told us how the grid command works, I can only guess, but you probably need to use %-2 for that segment instead of %2.
|
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
|
rtatum Novice
Joined: 19 Sep 2004 Posts: 45 Location: Houston
|
Posted: Sun Oct 10, 2004 9:06 pm |
Well, no... since %2 will always only be a single word... I don't know why it stopped working, but it works again now, but thanks anyways
|
|
|
|
|
|
|
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
|
|