PDA

View Full Version : anyInt function exists?



EvoloZz
8th February 2013, 19:27
Hello, i want to do something like this: for example if a variable has an number with i want to check if it has and i want any possible number, like this

if("variable" + anyInt)
something;

I dont know how to check for "any number".
I hope somebody can help, or someone even understands what i mean.

kung foo man
8th February 2013, 19:40
You can check for generated variable names in arrays:



level.ints = [];
level.ints["variable0"] = 0;
level.ints["variable1"] = 10;
level.ints["variable2"] = 20;
level.ints["variable3"] = 30;


if (isDefined(level.ints["variable" + 0])) // true


if (isDefined(level.ints["variable" + 10000])) // false

EvoloZz
8th February 2013, 19:56
Full thing of what i actually want:

onPlayerConnect()
{
for(;;)
{
if (player.name == "Player #" + anymumber) // Like it checks if the player has any numbers after the name
event;
}
}

serthy
8th February 2013, 20:21
if you only want to check if there is an integer BEHIND a name do this:

int = "";
for( i = string.size - 1 ; i >= 0 ; i-- )
{
if( !isSubStr( "0123456789" , string[i] ) )
break;
int += string[i];
}

int = int( int );

IzNoGoD
8th February 2013, 20:26
stripint(string)
{
newstring = "";
for(i = 0; i < string.size; i++)
{
if(!isint(string[i]))
newstring += string[i];
}
return newstring;
}

isint(char)
{
return issubstr("0123456789", char);
}


or, which i think you might ACTUALLY need:



checkifsame(string1, string2) //call like: checkifsame(player.name, "player #")
{
return issubstr(string1, string2);
}


Good luck :)