 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Jul 10, 2008 4:21 pm
Advanced find/replace |
Perhaps there could a find/replace function that goes through all aliases, variables, triggers etc... ? I know that if I move things to a different container, for instance. That I might suddenly need to change every instance of 2.spirit to 4.spirit or satchel to backpack. I can go through and find them all, but we all miss things. And if I have several aliases and triggers with a reference I'm more likely to miss one, not to mention the tediousness of it in the first place.
|
|
|
|
 |
Tech GURU

Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Jul 10, 2008 4:26 pm |
Something similar has been requested before... it may happen but it is way, way down on the wish list priority. Zugg has mentioned in the past that he doesn't want to focus a lot of priority into adding alot IDE specific features instead of MUDing features. He's actually gotten feedback that CMUD caters too much programmers/scripters and not enough to the average/casual MUD player.
|
|
_________________ Asati di tempari! |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Jul 10, 2008 4:27 pm |
Cater to both! But yeah, that makes sense, doesn't make the idea less appealing though!
|
|
|
|
 |
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Thu Jul 10, 2008 4:44 pm |
In the meantime why not define your container in a variable and then everywhere you refer to 2.spirit or whatever just use @container instead, then you have no need to find and replace you just have to change one variable, it is much easier.
|
|
_________________ Taz :) |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Jul 10, 2008 4:48 pm |
That's true enough. But now I'd have to replace it with the variable! 
|
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Jul 10, 2008 5:33 pm |
But you'd only have to do it once. The whole point of variables is that you use them for things that change often.
You could export your script to XML and do a textular find-replace on it, but you'd have to be careful it didn't match stuff that wasn't in the script part of something. It probably wouldn't, but you never know. |
|
|
|
 |
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Fri Jul 11, 2008 12:38 am |
<3 variables...I have the possibly bad habbit of putting lots of things into varibles. even when i'm 95% sure it will get used in one location, that way incase I do add it somewhere it's in a varible. And if you give your varibles good names...
| Code: |
| currenthealth=maxhealth - damage |
is lot easier to read than
Or what ever your case may be.
On other hand if you need to change say, a function call or a class... or more so out of luck, then I usualy export to xml find/replace, and import it back in. |
|
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Fri Jul 11, 2008 10:22 am |
| Fang Xianfu wrote: |
But you'd only have to do it once. The whole point of variables is that you use them for things that change often.
You could export your script to XML and do a textular find-replace on it, but you'd have to be careful it didn't match stuff that wasn't in the script part of something. It probably wouldn't, but you never know. |
I was joking  |
|
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Jul 11, 2008 11:54 am |
Sarcasm doesn't work on the internet :(
|
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Fri Jul 11, 2008 8:23 pm |
Hrm, isn't this why we have scripting, a Lua interface, and %subregex?! I guess I will take some time to write it for you.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Fri Jul 11, 2008 11:13 pm |
This will of course become part of toolbox package. I didn't do a final test of it where it would actually change anything in my settings because there was nothing I wanted changed. My testing was to display the changes it was going to make. The version that will be available in my toolbox will probably have some additional logging about what it did change and possibly a way to reverse the changes.
| Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="SearchAndReplace" copy="yes">
<value>#IF ($Search="") {#SHOW Search string required!;#EXIT}
#IF ($Replace="") {#SHOW Replacement string required!;#EXIT}
#IF ($Type="") {
$Type="alias|var|event|button|menu"
} {
$Type=%subregex($Type,"( |,)|(?:\b(?:(al(?:i(?:a(?:s)?)?)?)|(va(?:r(?:i(?:a(?:b(?:l(?:e)?))?)?)?)?)|(ev(?:e(?:n(?:t)?)?)?)|(bu(?:t(?:t(?:o(?:n)?)?)?)?)|(me(?:n(?:u)?)?)|(.*))\b)","(?(1)\||(?(2)alias|(?(3)var|(?(4)event|(?(5)button|(?(6)menu)|(?(7)ERROR\|\7))))))")
#DELITEM $Type {}
}
$ERROR=%ismember("ERROR",$Type)
#IF ($ERROR) {
#SHOW {Unknown type %item($Type,($ERROR+1))}
#EXIT
}
#IF (%yesno(%concat("Confirm replacement of ",$Search," with ",$Replace," in ",$Type))) {
#FORALL $Type {
#LUA %concat("i=zs.num",%i,%crlf,"while i>0 do",%crlf,"x=zs.get",%i,"(i)",%crlf,"y=x.value",%crlf,"x.value=zs.func.subregex(y,'",$Search,"','",$Replace,"')",%crlf,"i=i-1",%crlf,"end")
}
}</value>
<arglist>$Search, $Replace, $Type</arglist>
</alias>
</cmud> |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Fri Jul 11, 2008 11:29 pm |
I wasn't aware that I could do that...
|
|
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Jul 11, 2008 11:33 pm |
This is CMUD...you can do anything
I haven't figure out how to program it to mow my lawn yet, but I'm sure I could if I could find an Internet-enabled lawn-mower.
Btw Vijilante: Impressive script! |
|
|
|
 |
chamenas Wizard

Joined: 26 Mar 2008 Posts: 1547
|
Posted: Sun Jul 13, 2008 1:40 am |
It'll be a little while before I imp it, because I like to understand what I'm doing and I don't have time to look over it. But I trust Vigilante's script is nice. 
|
|
|
|
 |
ReedN Wizard
Joined: 04 Jan 2006 Posts: 1279 Location: Portland, Oregon
|
Posted: Sun Apr 26, 2009 4:52 pm |
I was playing around with a regular expression search and have run up against a roadblock I was hoping someone might have an idea about.
In the following code I print out the alias if either the name or the value contains the regular expression match. I'm using %regex to grab the line that matched so I don't display the whole alias.
I'd like to be able to display *each* line that matches from an alias and not just the first line as my code below performs. Any ideas on how to accomplish that? I know I could display the whole alias value contained in $value, but some aliases are very large and I'd like to avoid that.
| Code: |
$search = "here"
$count = %session.NumAliases
#LOOP 0,$count-1 {
$name = %session.AliasNum(%i).Name
$value = %session.AliasNum(%i).Value
#if (%regex( $name, $search) or %regex( $value, $search)) {
$matched = %null
#call %regex( $value, "(here.*)", $matched)
#print $name: $matched
}
}
|
|
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Fri May 15, 2009 8:27 am |
| Code: |
$search = "here"
$count = %session.NumAliases
#LOOP 0,$count-1 {
$name = %session.AliasNum(%i).Name
$value = %session.AliasNum(%i).Value
#if (%regex( $name, $search) {
#PRINT {Name match: $name}
#CONTINUE
}
$value=%subregex($value, %concat("(?:(?<Match>^(?>.*?)",$search,"(?>.*?(?:$|\z)))|^.*?(?:$|\z))", "(?(Match)(?INSTANCE): \'Match')")
#if ($value) {
#PRINT {Matches in alias: $name}
#PRINT $value
}
} |
If I didn't screw anything up that should display only lines that match, and should tack line numbers in front of the displayed lines. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
ReedN Wizard
Joined: 04 Jan 2006 Posts: 1279 Location: Portland, Oregon
|
Posted: Fri May 15, 2009 2:06 pm |
Thanks, I'll give that subregex a try!
|
|
|
|
 |
|
|
|