 |
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Fri Dec 13, 2002 11:40 pm
Letter replacement |
Hi all. I need help with a script, and I know I've seen the question answered before, but I can't for the life of me find it :( ... I'm sorry for asking again
I'm working on this quest, where I need to talk in a code of sorts ... i need a simple script where i can replace all instances of 'a' with 'x' ... and 'b' with 'r' etc ...
each letter to be replaced by another letter ...
I'd give you the translation exactly, but i don't want the mud wizards getting mad :/
thanks for the help
Father Horks
The only problem with computer security, is when you think it exists. |
|
|
 |
Kjata GURU

Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Dec 14, 2002 1:35 am |
What version are you using?
Kjata |
|
|
 |
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Sat Dec 14, 2002 3:51 am |
The latest beta.
Father Horks
The only problem with computer security, is when you think it exists. |
|
|
 |
Kjata GURU

Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Dec 14, 2002 3:54 am |
Well, then, this becomes really easy with the %subchar function. Example (copied from the help entry of %subchar):
quote:
#SHOW %subchar("hello world","hl","12")
displays "1e22o wor2d" where all "h" characters are replaced with "1" and all "l" characters are replaced with "2"
#SHOW %subchar("hello world","hl","")
displays "eo word" where all "h" and "l" characters are removed (replaced with nothing.
Kjata |
|
|
 |
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Sat Dec 14, 2002 4:24 am |
Ok, here's the script that i wrote, and it doesn't seem to be working right .. it's giving an answer, but not the correct answer
#VARIABLE trans %-1
#SHOW ENGLISH 2 LIZARDISH: %subchar( @trans, abcdefghijklmnopqrstuvwxyz, hmincjaobepdgfrswykzxtluqv)
when i try 'hi' it should produce 'ob' ... but instead, it produces 'qb' ... q is to be sub'd for y, not h ... any ideas?
UPDATED: second attempt, better test:
#SHOW %subchar( %1, "abcdefghijklmnopqrstuvwxyz", "hmincjaobepdgfrswykzxtluqv")
when i enter 'abcdefghijklmnopqrstuvwxyz' and i got 'qgbfceaqbekdgfqklqkvutluqv'
there's a whole lot of 'q' in there ... |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Dec 14, 2002 4:47 am |
Follow the example maybe?
#VARIABLE trans %-1
#SHOW ENGLISH 2 LIZARDISH: %subchar( @trans, "abcdefghijklmnopqrstuvwxyz", "hmincjaobepdgfrswykzxtluqv")
I have no way of testing it, but since the example shows quotes I'd expect unpredictable results from not using them.
LightBulb
Senior Member |
|
|
 |
horks Apprentice
Joined: 20 Jul 2001 Posts: 127 Location: USA
|
Posted: Sat Dec 14, 2002 4:52 am |
#SHOW %subchar( %1, "abcdefghijklmnopqrstuvwxyz", "hmincjaobepdgfrswykzxtluqv")
when i enter 'abcdefghijklmnopqrstuvwxyz' and i got 'qgbfceaqbekdgfqklqkvutluqv'
there's a whole lot of 'q' in there ...
this time i did use the "" and it still didn't work
Is there another way to do this? using a public version function? seems there are some problems with the %subchar function
(wrote this in an updated version of my previous post, but you had already responded :P wanted to bump my name to last posted)
Father Horks
The only problem with computer security, is when you think it exists. |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Dec 14, 2002 4:57 am |
Time to move to the beta forum then. This is a beta function, if its got a bug then Zugg needs to know about it.
LightBulb
Senior Member |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Dec 14, 2002 5:12 am |
As for the original problem, I'm sure it's possible but I suspect it will be a lot of work to get right. One approach would be to make two string variables, one (@string1) with the normal alphabet and the other (@string2) with the replacement alphabet. Your alias would then store %-1 to a third variable (@string3), then loop through that variable (@string3) replacing one character at a time. It would probably be easiest to save the replacement to a fourth variable (@string4). After finishing the loop, you can just "say @string4".
I suspect the problem with the %subchar function is that it loops through the first string doing a %replace for each character in turn. So "a" gets replaced with "h", but later that "h" gets replaced with "o", which gets replaced with "r", then "y", and finally "q".
LightBulb
Senior Member |
|
|
 |
Kjata GURU

Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Sat Dec 14, 2002 12:49 pm |
This is definately a bug in %subchar. I'll report this in the Beta Forum, and since a new version is just around the corner, I expect this to be fixed very soon.
The solution for 6.16 is as LightBulb mentioned. That is why I asked what version you had, because without %subchar the script is a lot more complicated and slower.
Kjata |
|
|
 |
|
|