Author Topic: Detecting a strings length.  (Read 1048 times)

How would I go about detecting a strings length for a customizable system.

Code: [Select]
function serverCmdCreateTribe(%client, %Tribename)
{
if(%Tribename//Stringlength > 10)
return;
//stuff
}


How would I go about detecting a strings length for a customizable system.

Code: [Select]
function serverCmdCreateTribe(%client, %Tribename)
{
if(%Tribename//Stringlength > 10)
return;
//stuff
}

Also, please format your code.

Code: [Select]
function serverCmdCreateTribe(%client, %Tribename)
{
    if(strLen(%Tribename) > 10)
return;

    //stuff
}

Yes, I usually do format my code but I was in quite a hurry while typing that. Anyway, thanks for the help.

P.S: One last question, instead of using a getRandom itself. How could I use something along it's lines but in a list. Such as...

Code: [Select]
[1]Possible Item = "CopperOre"
[2]Possible Item = "IronOre"
[3]Possible Item = "GoldOre"

function giverandomitem(%client)
{
//GetRandomItemFromList
%client.quantity[" PossibleItem "] += getRandom(1,10);
}
« Last Edit: May 24, 2009, 11:47:47 PM by Gorella »

Code: (TS) [Select]
PossibleItem[1] = "";
PossibleItem[2] = "";
PossibleItem[3] = "";

function giverandomitem(%client)
{
%randomkey = mCeil(getrandom() * 3));
%client.quantity[%randomKey] += mCeil(getrandom() * 10);
}

We use "%randomKey" to grab a random array key between 0 and 3, and round it up into an integer.


We use getrandom() to produce a random floating point decimal in between 0 and 1.

We multiply that by 10, so that it's between 0 and 10.

And we round it up so that it's an integer.
« Last Edit: May 25, 2009, 12:12:23 AM by Kalphiter »

We use "%randomKey" to grab a random array key between 0 and 3, and round it up into an integer.


We use getrandom() to produce a random floating point decimal in between 0 and 1.

We multiply that by 10, so that it's between 0 and 10.

And we round it up so that it's an integer.

Why are you feeding him your lack of knowledge?

Code: (TS) [Select]
PossibleItem[1] = "";
PossibleItem[2] = "";
PossibleItem[3] = "";

function giverandomitem(%client)
{
%randomkey = mCeil(getrandom() * 3));
%client.quantity[%randomKey] += mCeil(getrandom() * 10);
}

We use "%randomKey" to grab a random array key between 0 and 3, and round it up into an integer.


We use getrandom() to produce a random floating point decimal in between 0 and 1.

We multiply that by 10, so that it's between 0 and 10.

And we round it up so that it's an integer.

Or we can do it the easy way, and actually make it work.

Code: (TS) [Select]
$PossibleItem[$MaxItems++] = "";
$PossibleItem[$MaxItems++] = "";
$PossibleItem[$MaxItems++] = "";

function giverandomitem(%client)
{
%tool = $PossibleItem[getRandom(1,$MaxItems)];
for(%i=0;%i<%client.player.getDataBlock().maxTools; %i++)
{
if(%client.player.tool[%i] == 0)
{
%client.player.tool[%i] = %tool;
if(%tool.className $= "Weapon")
%client.player.weaponCount++;
messageClient(%client,'MsgItemPickup','',%i,%tool);
break;
}
}
}

Or we can do it the easy way, and actually make it work.

Code: (TS) [Select]
$PossibleItem[$MaxItems++] = "";
$PossibleItem[$MaxItems++] = "";
$PossibleItem[$MaxItems++] = "";

function giverandomitem(%client)
{
%tool = $PossibleItem[getRandom(1,$MaxItems)];
for(%i=0;%i<%client.player.getDataBlock().maxTools; %i++)
{
if(%client.player.tool[%i] == 0)
{
%client.player.tool[%i] = %tool;
if(%tool.className $= "Weapon")
%client.player.weaponCount++;
messageClient(%client,'MsgItemPickup','',%i,%tool);
break;
}
}
}
No, you just missed the point. They're not supposed to give actual tools(items). So, read his outline again.

And the rest is just preference.

PossibleItem[1] = "";
PossibleItem[2] = "";
PossibleItem[3] = "";

function giverandomitem(%client)
{
   %randomkey = mCeil(getrandom() * 3));
   %client.quantity[%randomKey] += mCeil(getrandom() * 10);
}


Syntax errors. Its quite funny how there's always something wrong with what you do - take some pride in your work.

Syntax errors. Its quite funny how there's always something wrong with what you do - take some pride in your work.
It's quite funny how I copied directly from what he did.

Not really.

Code: [Select]
[1]Possible Item = "CopperOre"
[2]Possible Item = "IronOre"
[3]Possible Item = "GoldOre"

function giverandomitem(%client)
{
//GetRandomItemFromList
%client.quantity[" PossibleItem "] += getRandom(1,10);
}
Code: (TS) [Select]
PossibleItem[1] = "";
PossibleItem[2] = "";
PossibleItem[3] = "";

function giverandomitem(%client)
{
%randomkey = mCeil(getrandom() * 3));
%client.quantity[%randomKey] += mCeil(getrandom() * 10);
}


You mean half Java half Torquescript?

You mean half Java half Torquescript?
Yes; Here is a snippet of Java:


Code: (Java) [Select]
int PossibleItem = new int[4];
PossibleItem[3] = "Copper";

Ok, I'm totally confused, I'm going to try Chrono's code and try to tinker a bit with it.