<< Script for Quick texts >> |
Author: |
Message: |
Jimbo
Veteran Member
Posts: 1650 Reputation: 18
32 / /
Joined: Jul 2006
|
RE: << Script for Quick texts >>
Sorry, i forgot i couldn't put ' after a return
use this instead:
code: function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 4)== "test"){
return'test1'
}
if (Message.substr(0, 4) == "cant"){
return'can"t'
}
if (Message.substr(0, 4) == "dont"){
return'don"t'
}
}
|
|
01-06-2007 11:46 AM |
|
|
NanaFreak
Scripting Contest Winner
Posts: 1476 Reputation: 53
32 / /
Joined: Jul 2006
|
RE: << Script for Quick texts >>
ok i have fixed up my brothers code
code: var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(original[i],changed[i]);
}
return Message;
}
there you go (tested and it works)
jimbodude this is the better way.... just leave to to the pros
|
|
01-06-2007 12:12 PM |
|
|
Chestah
Veteran Member
Posts: 1658 Reputation: 34
36 / / –
Joined: Jun 2004
|
RE: << Script for Quick texts >>
quote: Originally posted by Jimbodude
Sorry, i forgot i couldn't put ' after a return
use this instead:
code: function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 4)== "test"){
return'test1'
}
if (Message.substr(0, 4) == "cant"){
return'can"t'
}
if (Message.substr(0, 4) == "dont"){
return'don"t'
}
}
Use nanafreak's code, the code above is verbose and unneccesarily long when you are working with alot of words and its biggest disadvantage is that it only parses the word if it is the first thing that is typed (and also only does one word).
ie 'dont' will get changed into 'don't'
but if you typed 'hello!! hey, dont do that', it will not be parsed.
|
|
01-06-2007 12:28 PM |
|
|
Double_N2
New Member
Posts: 10
Joined: Jan 2007
|
O.P. RE: << Script for Quick texts >>
Thanks everyone.
this one is working.
var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(original[i],changed[i]);
}
return Message;
}
|
|
01-06-2007 01:02 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: << Script for Quick texts >>
Again, nobody succeeded in giving the right code.
code: //By Jimbodud
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0, 4)== "test"){
return'test1'
}
if (Message.substr(0, 4) == "cant"){
return'can't'
}
if (Message.substr(0, 4) == "dont"){
return'don't'
}
}
This code will only match if the word is in front, and will forget the rest of the message. Example: "cant do that" gives "can't" without the "do that".
code: //By NanaFreak
var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(original[i],changed[i]);
}
return Message;
}
This code is better, only it's case-sensitive and it'll only replace one occurrence per array element. That's why markee was using RegExp's. So, the code which should do it:
code: var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(RegExp(original[i], "gi"), changed[i]);
}
return Message;
}
|
|
01-06-2007 02:09 PM |
|
|
markee
Veteran Member
Posts: 1622 Reputation: 50
36 / /
Joined: Jan 2006
|
RE: RE: << Script for Quick texts >>
quote: Originally posted by Mattike
That's why markee was using RegExp's. So, the code which should do it:
code: var original = new Array("dont","cant","test");//what you are changing from
var changed = new Array("don't","can't","test1");//what you are changing to
function OnEvent_ChatWndSendMessage(ChatWnd,Message){
for(i in original){
Message = Message.replace(RegExp(original[i], "gi"), changed[i]);
}
return Message;
}
Exactly, all I forgot was to re-define Message
* markee writes note to always use the scripting engine now on before posting any code
|
|
01-06-2007 04:00 PM |
|
|
Tochjo
forum super mod
Posts: 4207 Reputation: 78
37 / /
Joined: Sep 2003
|
RE: << Script for Quick texts >>
The two threads were merged and several posts were deleted. I hope the discussion can continue here without much problems
|
|
01-06-2007 05:26 PM |
|
|
Pages: (2):
« First
«
1
[ 2 ]
Last »
|
|
|