Blockland Forums > Modification Help
Converting chat to URL efficiently.
Truce:
I've only tested this briefly, so just tell me if you come across any errors.
What it does is it converts as much as it can (see: code) into "URL chat."
I don't know if it's all that optimized, as it's sixty lines of loopy goodness.
--- Code: ---function makeURLd(%str)
{
%cnt = getWordCount(%str);
for(%i = 0; %i < %cnt; %i++)
{
if(strPos(getWord(%str,%i),":") != -1)
%idx[%i] = 1;
}
for(%i = 0; %i < %cnt; %i++)
{
%wrd = getWord(%str,%i);
%tmp = %tmp @ %wrd;
if(!%idx[%i + 1] && !%idx[%i])
%tmp = %tmp @ "\x90";
else
%tmp = %tmp @ " ";
}
%tmp = getSubStr(%tmp,0,strLen(%tmp) - 1);
%cnt = getWordCount(%tmp);
for(%i = 0; %i < %cnt; %i++)
{
%wrd = getWord(%tmp,%i);
if(strPos(%wrd,":") != -1)
continue;
%len = strLen(%wrd);
if(%len > %len1)
{
%len2 = %len1;
%idx2 = %idx1;
%len1 = %len;
%idx1 = %i;
}
else if(%len > %len2)
{
%len2 = %len;
%idx2 = %i;
}
}
for(%i = 0; %i < %cnt; %i++)
{
%wrd = getWord(%tmp,%i);
if(%i $= %idx1 || %i $= %idx2)
%url = %url @ "http://" @ strReplace(%wrd,"\x90","_") @ " ";
else
%url = %url @ strReplace(%wrd,"\x90"," ") @ " ";
}
return getSubStr(%url,0,strLen(%url) - 1);
}
--- End code ---
Input:
--- Quote ---hi connect to 127.0.0.1:1234 please :) thank you!
--- End quote ---
Output:
--- Quote ---http://hi_connect_to 127.0.0.1:1234 please :) http://thank_you!
--- End quote ---
(It didn't prefix "please" with http:// because the "thank you!" phrase was longer. All this code assumes you were correct when you said that Blockland chat allows for two URLs - no more, no less - and affects up to two of the longest colonless phrases. I haven't actually tested it ingame, only via the console (dedicated LAN's), so if you're wrong about that then the code probably doesn't work ingame. Can be altered though.)
Uristqwerty:
What are you trying to do? If you gave an example or two of input and output that you want, it would be easier to help.
Truce:
I just tested it ingame and saw that the chat only supports one URL by default. Just take out the code that I put in to account for the second longest portion and it works perfectly. (If you don't remove it, it still works perfectly as long as the chat supports two URLs, which is what it was originally designed for.)
MegaScientifical:
It should still find the longest portion. Just not make more than one URL. And I must still point out that I said:
--- Quote ---[01:12:15] MegaScience: Trigun :(
--- End quote ---
It came out:
--- Quote ---[01:12:15] MegaScience: Trigun http://:(
--- End quote ---
in chat... Might need that fixed.
Truce:
--- Quote from: MegaScientifical on October 23, 2010, 06:16:34 PM ---It should still find the longest portion. Just not make more than one URL.
--- End quote ---
If you remove the second longest one then it still finds the first longest one. Like I said, it works.
--- Quote from: MegaScientifical on October 23, 2010, 06:16:34 PM ---And I must still point out that I said:
It came out:
in chat... Might need that fixed.
--- End quote ---
It shows up as "http://Trigun :(" for me (how it should). You're probably implementing it wrong.