What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » a problem scripting :/ [NOW SOLVED THANKS]

a problem scripting :/ [NOW SOLVED THANKS]
Author: Message:
Red King
Junior Member
**


Posts: 21
– / Male / –
Joined: Feb 2007
O.P. a problem scripting :/ [NOW SOLVED THANKS]
hey i'm kinda new to scripting but i knw one thing that should be pretty easy..yet it dont do it right..text replacement
some letters i try to have replaced work the way they should but many many others don't

the replacements go for example

Message = Message.replace(/a/gi,"(other wanted character)");

as the part that would replace a sertain piece of text

some of these work but most of my list just randomises the letter it becomes

i was trying to re-create the al bhed translators of final fantasy 10 into an msn script.. which i thougt i had working until i saw most of my letters were made wrong after i finished writing the script

what i was trying to make was
a b c d e f g h i j k l m n o p q r s t u v w x y z =
y p l t a v k r e z g m s h u b x n c d i j f q o w
as my wa of shortcutting to al bhed from the game

but instead when i test the finished script i'd end up with something rediculous like 3 S's 2 T's a few J's and maybe a Q where it belongs and everything lse is random scatter

can anyone help me out here? :S

This post was edited on 02-14-2007 at 09:19 PM by Red King.
02-13-2007 10:14 PM
Profile E-Mail PM Find Quote Report
pollolibredegrasa
Full Member
***

Avatar
formerly fatfreechicken

Posts: 483
Reputation: 34
35 / Male / Flag
Joined: May 2005
RE: a problem scripting :/
It's because when you replace A with Y for example, when it comes to replace the letter Y it will then replace it again with the letter O. You're replacing letters multiple times...

A > Y > O

Not sure how best to explain it :s

Edit: see here

This post was edited on 02-13-2007 at 10:25 PM by pollolibredegrasa.
02-13-2007 10:23 PM
Profile PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: a problem scripting :/
What is probably happening is the following:
+Your script searches for any occurences of "a"
+Your script finds "a" and replaces it with "b"
+Your script searches for "b"
+Your script finds "b", including the "b" that originally was an "a", and replaces it with "c".

The better way to replace letters where there is a possibility of the replacement letter being replaced itself (if that makes any sense outside of my head) is to just loop through each letter in the string.

e.g.
code:
var teststring = "Hello World";
var testarray = teststring.split(""); //convert string into an array
for(i=0;i<testarray.length;i++){
  //do replacing here, get current character with testarray[i];
}
teststring = testarray.join(""); //convert array back to a string

02-13-2007 10:24 PM
Profile PM Find Quote Report
Red King
Junior Member
**


Posts: 21
– / Male / –
Joined: Feb 2007
O.P. RE: a problem scripting :/
but if that's how it goes then wouldn't the whole thing not do anything at all?
because if A>Y>O happens then it'll continue on to U> everything else going on a loop right?

edit:
so what you're saying is a text format code in the replacement character might work?
if it's not then that idea just randomly popped up and i think it's gonna rescur my script thanks ^^

This post was edited on 02-13-2007 at 10:28 PM by Red King.
02-13-2007 10:25 PM
Profile E-Mail PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: a problem scripting :/
This is because you will just be doing one replace after the other on the one string. For example if you had the string "ABC" and replaced "A" with "B" and then "B" with "C" you will just end up with "CCC" rather than the "BCC" you were after.

To overcome this you will have to put the changes into a new variable.  This code should help with what you need (using what you have written).

code:
var alpha = "abcdefghijklmnopqrstuvwxyz";
var code = "ypltavkrezgmshubxncdijfqow";
var Split = Message.split("");
var eSplit = new Array();
for(i=0;i<Split.length;i++){
    for(j=0;j<alpha.length;j++){
        if(Split[i] == alpha.charAt(j)){
            eSplit[i] = code.charAt(j);
            break;
        }
if(j == alpha.length){
eSplit[i] = Split[i];
}
    }
}
var eMessage = eSplit.join("");
Debug.Trace(eMessage);

I hope this extract helps you.

EDIT: Forgot to pass other characters, all fixed now though.

This post was edited on 02-14-2007 at 11:07 PM by markee.
[Image: markee.png]
02-13-2007 10:39 PM
Profile PM Find Quote Report
Red King
Junior Member
**


Posts: 21
– / Male / –
Joined: Feb 2007
O.P. RE: RE: a problem scripting :/
quote:
Originally posted by markee
This is because you will just be doing one replace after the other on the one string. For example if you had the string "ABC" and replaced "A" with "B" and then "B" with "C" you will just end up with "CCC" rather than the "BCC" you were after.

To overcome this you will have to put the changes into a new variable.  This code should help with what you need (using what you have written).

code:
var alpha = "abcdefghijklmnopqrstuvwxyz";
var code = "ypltavkrezgmshubxncdijfqow";
var Split = Message.split("");
var eSplit = new Array();
for(i=0;i<Split.length;i++){
    for(j=0;j<alpha.length;j++){
        if(Split[i] == alpha.charAt(j)){
            eSplit[i] = code.charAt(j);
            break;
        }
    }
}
var eMessage = eSplit.join("");
Debug.Trace(eMessage);

I hope this extract helps you.

thank you :)
i really appreciate it i'll try it out now

edit: i tried that and it's not replacing anything now is there anything else i'm supposed to add to all this?

This post was edited on 02-13-2007 at 10:59 PM by Red King.
02-13-2007 10:48 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: a problem scripting :/
quote:
Originally posted by Red King
edit: i tried that and it's not replacing anything now is there anything else i'm supposed to add to all this?
markee's code outputs the text in the debugging window. If you'd know how to script, you'd probably have seen that... :dodgy:

Anyways, replace
code:
Debug.Trace(eMessage);
with
code:
return eMessage;
according that you're working in the OnEvent_ChatWndSendMessage event.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-14-2007 02:18 PM
Profile E-Mail PM Web Find Quote Report
Red King
Junior Member
**


Posts: 21
– / Male / –
Joined: Feb 2007
O.P. RE: RE: a problem scripting :/
quote:
Originally posted by Mattike
quote:
Originally posted by Red King
edit: i tried that and it's not replacing anything now is there anything else i'm supposed to add to all this?
markee's code outputs the text in the debugging window. If you'd know how to script, you'd probably have seen that... :dodgy:

Anyways, replace
code:
Debug.Trace(eMessage);
with
code:
return eMessage;
according that you're working in the OnEvent_ChatWndSendMessage event.

alrighty then thanks for the info i'll try it now
aaand like i said before i don't know very well i'm kinda new
only started yesterday so i might be needing help for a while ^^;
i should soon get the hang of it though i learn most things kinda quick

edit: HURRAY thank you it works now it's just not giving me my spaces which i guess needs to be put in the character list or something so i'm about to do that now
thank you all guys for helping me out i promise i'll practice and make myself better so you aint stuck always helping me o.o;;

edit again XD: all done now and yes the no space problem was my A-Z's bot not having a space in the character list which is now done
thanks again guys i really appreciate your help

This post was edited on 02-14-2007 at 09:15 PM by Red King.
02-14-2007 08:47 PM
Profile E-Mail PM Find Quote Report
markee
Veteran Member
*****

Avatar

Posts: 1622
Reputation: 50
36 / Male / Flag
Joined: Jan 2006
RE: a problem scripting :/ [NOW SOLVED THANKS]
I'll fix up my code above for you, I'm sorry for forgetting something like that.  It will just carry down any other characters.

EDIT: All fixed, and I'm sorry for not explaining the eMessage thing.  I just used that so as you still had the original message if you needed it for something.

This post was edited on 02-14-2007 at 11:08 PM by markee.
[Image: markee.png]
02-14-2007 11:04 PM
Profile PM Find Quote Report
Red King
Junior Member
**


Posts: 21
– / Male / –
Joined: Feb 2007
O.P. RE: a problem scripting :/ [NOW SOLVED THANKS]
well it's all fixed up and working fine on my ed
i fized it up with that little edit and added every chracter useable into the replacement list so they all work the same..
this is what the translation area has become instead of just a-z lower case
code:
var alpha = " !#~?/.>,<\|@':[{]}`£$%^&*()_+=-0987654321abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var code = " !#~?/.>,<\|@':[{]}`£$%^&*()_+=-0987654321ypltavkrezgmshubxncdijfqowYPLTAVKREZGMSHUBXNCDIJFQOW";
02-14-2007 11:09 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On