Results 1 to 5 of 5

Thread: anyInt function exists?

  1. #1
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts

    anyInt function exists?

    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
    Code:
    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.

  2. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    You can check for generated variable names in arrays:

    Code:
    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
    timescale 0.01

  3. #3
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Full thing of what i actually want:
    Code:
    onPlayerConnect()
    {
        for(;;)
        {
            if (player.name == "Player #" + anymumber) // Like it checks if the player has any numbers after the name
            event;
        }
    }

  4. #4
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    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 );

  5. The Following 2 Users Say Thank You to serthy For This Useful Post:

    EvoloZz (8th February 2013),kung foo man (8th February 2013)

  6. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Code:
    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:

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

  7. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    EvoloZz (8th February 2013),kung foo man (8th February 2013)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •