quote:
Originally posted by roflmao456
* roflmao456 calls Cookie to explain
Whooosh..
For things like this many people use the Replace function. But the replace function will search for the stuff to replace from the beginning of the text you paste to it.
So, in a list if you have the letters A B C D E F G H and you're going to replace each letter respectivly with C D E F G H A B... Then you can (and will) come in the situation like this:
The next pseudo code is almost always used in scripts like this (you can verify this in the scripting database). But it will, in most cases, render wrong results:
var myword = "ABC"
myword = myword.replace("A", "C")
myword = myword.replace("B", "D")
myword = myword.replace("C", "E")
myword = myword.replace("D", "F")
myword = myword.replace("E", "G")
myword = myword.replace("F", "H")
myword = myword.replace("G", "A")
myword = myword.replace("H", "B")
myword is now "EBC"
(1) or "ABA"
(2) not "CDE" as it was intended!
This because:
(1) if Replace replaced the first letter it finds (like it does by default):
var myword = "ABC"
myword = myword.replace("A", "C") => myword is now "
CBC"
myword = myword.replace("B", "D") => myword is now "C
DC"
myword = myword.replace("C", "E") => myword is now "
EDC"
(here the first error occurs)
myword = myword.replace("D", "F") => myword is now "E
FC"
myword = myword.replace("E", "G") => myword is now "
EFC"
myword = myword.replace("F", "H") => myword is now "E
HC"
myword = myword.replace("G", "A") => myword is still "EHC"
myword = myword.replace("H", "B") => myword is now "E
BC"
or, (2) if Replace replaced all the letters it finds:
var myword = "ABC"
myword = myword.replace("A", "C") => myword is now "
CBC"
myword = myword.replace("B", "D") => myword is now "C
DC"
myword = myword.replace("C", "E") => myword is now "
ED
E"
(here the first error occurs)
myword = myword.replace("D", "F") => myword is now "E
FE"
myword = myword.replace("E", "G") => myword is now "
GF
G"
myword = myword.replace("F", "H") => myword is now "G
HG"
myword = myword.replace("G", "A") => myword is now "
AH
A"
myword = myword.replace("H", "B") => myword is now "A
BA"
Conclussion: never ever use:
var myword = "something"
myword = myword.replace("A", "B")
myword = myword.replace("B", "C")
myword = myword.replace("C", "A")
or the likes (like looping using a list, as this is just the same, only shorter in code) to replace text when the text to search for contains the same characters as the text to replace with!
-------------------------
quote:
Originally posted by Yukai
But why FirstWord and SecondWord? Are they linked with Kanjiword and SecondKanjiWord?
Let's say that:
FirstWord gets changed to A
KanjiWord gets changed to B
Will "A" then become "B" when i type and will an incoming "B" become "A"?
yep
But only if Kanji and Romaji don't have any words in common (or even parts of words!!). Otherwise you will have the situation as described above. Which means you will not be able to use that script for this.
Though, there are other situations in which this script will not work properly and this has got something to do with the RecievedMessage event and detecting if the recieved message is/isn't a message you wrote. But that's explained in another thread
And then there is also the fact that you can not return a longer message than the one you've recieved in the RecievedMessage event. Which can and will also lead to this script not working properly in those cases.
-------------------------
This said, it could be possible that there is a Windows API which already does this convertion, I can't remember anymore, I'll need to look this up (unless someone else can confirm this or not). > EDIT: after an extremely quick plain search I can't find any api for this though...