Author Topic: Detecting Larger Center Print  (Read 1010 times)

How can I detect if a center print size is larger than 23 and change it if it is?

Search for <font:, locate next colon, locate next greater than sign after it, find size, replace if too big?

Like this?
Code: [Select]
package CenterPrintRestriction
{
function clientCmdCenterPrint(%words, %number)
{
%font = getLoc(%words, "<font:");
%nextColon = getLoc(%words, ":", %font);
%nextGreat = getLoc(%words, ">", %nextColon);
%num = %nextColon - %nextGreat;

if(%font)
{
if(%num >= 65)
{
strReplace(%words, %num, 64);
}
}

parent::clientCmdCenterPrint(%words, %number);
}
};
activatePackage(CenterPrintRestriction);

function getLoc(%string, %search, %x)
{
if(trim(%x) !$= "")
{
for(%i = %x; %i < strLen(%string); %i++)
{
if(%i + strLen(%search) $= %search)
{
return %i;
}
}
}

else
{
for(%i = 0; %i < strLen(%string); %i++)
{
if(%i + strLen(%search) $= %search)
{
return %i;
}
}
}

return -1;
}

Yes, except your makeshift getLoc function won't work. Just use strPos. Also, if ( %font ) wouldn't run if <font: was at position 0.

What the hell are you doing..
How do you expect to get the font size by subtracting the colon position by the greater than sign position? Use getSubStr. Also, you're replacing every instance of the number with something else.
« Last Edit: June 15, 2012, 11:30:37 AM by Port »

How do you expect to get the font size by subtracting the colon position by the greater than sign position?
Umm idk.
Use getSubStr.
Where?
Also, you're replacing every instance of the number with something else.
Yep.

Where?
Use it instead of getLoc

Use this code
Code: [Select]
function limitStrTxtSize(%string,%limit)
{
    %firstArrowPos = strPos(%string,"<font:");
    %secondColonPos = strPos(%string,":",%firstArrowPos + 5);
    %secondArrowPos = strPos(%string,">",%secondColonPos);
    %size = getSubStr(%string,%secondColonPos + 1,%secondArrowPos - %secondColonPos - 1);
    if(%size > %limit)
    {
        if(%firstArrowPos != 0)
            %before = getSubStr(%string,0,%firstArrowPos);
        if(%secondArrowPos != strLen(%string) - 1)
            %after = getSubStr(%string,%secondArrowPos + 1,strLen(%string) - %secondArrowPos - 1);
        %during = getSubStr(%string,%firstArrowPos,%secondColonPos - %firstArrowPos + 1) @ %limit @ ">";
        return %before @ %during @ %after;
    }
}
« Last Edit: June 16, 2012, 02:44:37 PM by Treynolds416 »

Use it instead of getLoc

No, instead of position subtraction. He should use something such as strPos for what you mentioned.

No, instead of position subtraction. He should use something such as strPos for what you mentioned.
Right, my bad

No, instead of position subtraction. He should use something such as strPos for what you mentioned.
Like this?
Code: [Select]
package CenterPrintRestriction
{
//Max center print size is 64
//23 is the max size you can handle

function clientCmdCenterPrint(%words, %num)
{
%font = strPos(%words, strLen("<font:"));
%nextColon = strPos(%words, ":", strLen(%font) + 6);
%nextGreat = strPos(%words, ">", strLen(%nextColon) + 1);
%size = %nextColon - %nextGreat;

if(%font)
{
if(%size >= 65)
{
%words = strReplace(%words, %size, 64);
}
}

parent::clientCmdCenterPrint(%words, %num);
}
};
activatePackage(CenterPrintRestriction);

Like this?
Code: [Select]
package CenterPrintRestriction
{
//Max center print size is 64
//23 is the max size you can handle

function clientCmdCenterPrint(%words, %num)
{
%font = strPos(%words, strLen("<font:"));
%nextColon = strPos(%words, ":", strLen(%font) + 6);
%nextGreat = strPos(%words, ">", strLen(%nextColon) + 1);
%size = %nextColon - %nextGreat;

if(%font)
{
if(%size >= 65)
{
%words = strReplace(%words, %size, 64);
}
}

parent::clientCmdCenterPrint(%words, %num);
}
};
activatePackage(CenterPrintRestriction);
That would replace every instance of the size with 64

That would replace every instance of the size with 64
Well how do I only replace it if the size is larger than 64?

Well how do I only replace it if the size is larger than 64?

No offense, but is there something wrong with your brain or do you just not know what you are even doing yourself?

No offense, but is there something wrong with your brain or do you just not know what you are even doing yourself?
I just don't even know myself what I'm doing.

Well how do I only replace it if the size is larger than 64?
Use my code

You can use my custom TML parser for this.

I set it up for you to do what you need:
Code: [Select]
function parseML(%flag)
{
for(%i=0; %i < strLen(%flag); %i++)
{
%char = getSubStr(%flag,%i,1);

if(%char $= "<")
%start = %i;

if(%char $= ">" && %start !$= "")
{
%end = %i;

%full = getSubStr(%flag,%start,%end-%start+1);
%contents = getSubStr(%full,1,strLen(%full) - 2);

%search = %contents;
%pos = -1;
%numValues = 0;
while(strPos(%search,":") >= 0)
{
%search = getSubStr(%search,%pos+1,strLen(%search));

%pos = strPos(%search,":");
if(%pos >= 0)
{
%value[%numValues] = getSubStr(%search,0,%pos);
}
else
{
%value[%numValues] = %search;
}
%numValues ++;
}

if(%numValues <= 0)
{
if(%contents !$= "")
{
%value[0] = %contents;
%numValues = 1;
}
}

%replace = parseMLReplace(%value0,%value1,%value2,%value3,%value4,%value5,%value6,%value7,%value8,%value9,%value10,%value11,%value12,%value13,%value14,%value15);

if(%replace !$= "")
{
%flag = strReplace(%flag,%full,%replace);
%i = %start-1;
}

%start = "";
%end = "";
%full = "";
%contents = "";
%search = "";
%replace = "";
for(%e=0; %e < %numValues; %e++)
%value[%e] = "";
%numValues = "";
}
}

return %flag;
}

function parseMLReplace(%value0,%value1,%value2,%value3,%value4,%value5,%value6,%value7,%value8,%value9,%value10,%value11,%value12,%value13,%value14,%value15)
{
switch$(%value[0])
{
case "font":
if(%value[2] > 64)
{
%replace = "<font:" @ %value[1] @ ":64>";
}
}

return %replace;
}