How can i specify specific alphabetical character or Specific number

Started by Kelvinvenema, Feb 04, 2020, 04:34 PM

Previous topic - Next topic

Kelvinvenema

Hello, guys, can someone help me out I have tried my best to find something related to Alphabetical character but I found nothing.
I already know how I can use IsNum:
But I would like to know how I can specify a certain  number like 1 or 9 //  or character like A or Z

I tried doing this for IsNum:

if(IsNum == 5) MessagePlayer ("You have typed number 5", player );

it won't work.
I don't know if there is a value I can use to specify a character for example

if(Charac == 'a') MessagePlayer("You have typed A",player);

Anyways thanks for reading greets Kelvin.

D4rkR420R

It should be...
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );BTW, where are you running that line?

MatheuS

if(IsNum == 5) MessagePlayer ("You have typed number 5", player );
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );
if(Charac == 'a') MessagePlayer("You have typed A",player);
if(text.find( "a" ) != null ) MessagePlayer("You have typed A",player);
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

Kelvinvenema

Quote from: DarkRaZoR^ on Feb 04, 2020, 04:49 PMIt should be...
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );BTW, where are you running that line?


Where I am running the function:  onPlayerCommand(player, command, arguments)

I was testing something out to specify and return certain values
and it is now working
Thanks :)

Kelvinvenema

Quote from: MatheuS on Feb 04, 2020, 05:22 PMif(IsNum == 5) MessagePlayer ("You have typed number 5", player );
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );
if(Charac == 'a') MessagePlayer("You have typed A",player);
if(text.find( "a" ) != null ) MessagePlayer("You have typed A",player);


I really appreciate your help thanks :)

Kelvinvenema

Quote from: MatheuS on Feb 04, 2020, 05:22 PMif(IsNum == 5) MessagePlayer ("You have typed number 5", player );
if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );
if(Charac == 'a') MessagePlayer("You have typed A",player);
if(text.find( "a" ) != null ) MessagePlayer("You have typed A",player);



I have tried using the if( IsNum("5") ) MessagePlayer( "You have typed number 5", player );
I thought it worked when it pressed the button it outputted the right number but it also sends a message when the number isn't 5 what is wrong with the line it doesn't give me any errors


DraGone

You just need to use IsNum() function if you want to check whether the text is a number..

You dont necessarily need to check whether the text is number if you just want to compare two string. You can just do it right away, e.g:
function onPlayerCommand(player, command, text)
{
// Remember, 'text' is a string by default, no matter you typed a number or anything
// Or it is simply null if player left it empty

if ( command == "test" )
{
/* Only proceed if 'text' is not null because we cant compare 'null' with a string */
if ( text != null )
{
/* Compare the 'text' with string '5', notice "5" is a string not integer */
if ( text == "5" ) PrivMessage( player, "You just typed: 5" );
else if ( text == "a" ) PrivMessage( player, "You just typed: a" );
}
}
}

You just need to use IsNum if you really want and need the text to be number, e.g.
function onPlayerCommand(player, command, text)
{
if ( command == "givemecash" )
{
/* Only proceed if 'text' is not null because IsNum function only accept string */
if ( text != null )
{
/* Check whether the 'text' is a number using IsNum function */
/* If it return true, that means the the text is indeed a number */
if ( IsNum( text ) == true )
{
/* Convert 'text' from string to integer. In this example we are going to increase player's cash so it must be integer */
text = text.tointeger( );

/* Compare 'text' with integer 0, we can compare it with integer cuz we already converted it to integer just now */
if ( text <= 0 ) PrivMessage( player, "Hey, the amount must be higher than 0!" );
else
{
player.Cash += text;
PrivMessage( player, "You just got $"+ text +"!" );
}
}
else
{
PrivMessage( player, "Hey, "+ text +" is not a number!" );
}
}
else PrivMessage( player, "Please specify how much you need" );
}
}

The codes above are untested, it's just an example!

Kelvinvenema

Quote from: DraGone on Feb 05, 2020, 04:09 AMYou just need to use IsNum() function if you want to check whether the text is a number..

You dont necessarily need to check whether the text is number if you just want to compare two string. You can just do it right away, e.g:
function onPlayerCommand(player, command, text)
{
// Remember, 'text' is a string by default, no matter you typed a number or anything
// Or it is simply null if player left it empty

if ( command == "test" )
{
/* Only proceed if 'text' is not null because we cant compare 'null' with a string */
if ( text != null )
{
/* Compare the 'text' with string '5', notice "5" is a string not integer */
if ( text == "5" ) PrivMessage( player, "You just typed: 5" );
else if ( text == "a" ) PrivMessage( player, "You just typed: a" );
}
}
}

You just need to use IsNum if you really want and need the text to be number, e.g.
function onPlayerCommand(player, command, text)
{
if ( command == "givemecash" )
{
/* Only proceed if 'text' is not null because IsNum function only accept string */
if ( text != null )
{
/* Check whether the 'text' is a number using IsNum function */
/* If it return true, that means the the text is indeed a number */
if ( IsNum( text ) == true )
{
/* Convert 'text' from string to integer. In this example we are going to increase player's cash so it must be integer */
text = text.tointeger( );

/* Compare 'text' with integer 0, we can compare it with integer cuz we already converted it to integer just now */
if ( text <= 0 ) PrivMessage( player, "Hey, the amount must be higher than 0!" );
else
{
player.Cash += text;
PrivMessage( player, "You just got $"+ text +"!" );
}
}
else
{
PrivMessage( player, "Hey, "+ text +" is not a number!" );
}
}
else PrivMessage( player, "Please specify how much you need" );
}
}

The codes above are untested, it's just an example!

Thanks, you now I understand how I can interpret them in my codes and my commands
Using this

local TextSplit = split( text, " " ),let1=TextSplit[ 0 ],num1=TextSplit[ 1 ];

I can name my text whatever I want
for example

  local TextSplit = split( text, " " ),let1=TextSplit[ 0 ],num1=TextSplit[ 1 ];
   if (( let1 == "5") && (num1 == "a")) PrivMessage( player, "You just typed: "+let1+", "+num1+" " );