AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Empty string? How can I check? (https://forums.alliedmods.net/showthread.php?t=156456)

killergirl 05-06-2011 17:45

Empty string? How can I check?
 
I'm building up a plugin that saves data into a file. The problem is with the number of arguments. I'm trying to save 4 values (IT WORKS) but, If I execute the command with 3 values, the data line is also created, but with 3 values I can't make anything (for different functions). Anyway... this is the code:

PHP Code:

public function(idlvlcid)
{
   if(!
cmd_access(idlvlcid4))
      return 
PLUGIN_HANDLED

   read_argv
(1argOne31)
   
read_argv(2argTwo31)
   
read_argv(3argThree31)
   
read_argv(4argFour31)


I know I can't have 4 arguments, but maybe is there a way to use 4 arguments.

Hunter-Digital 05-06-2011 18:20

Re: Empty string? How can I check?
 
Title says a different thing... but anyway: if(strlen(string) > 0) or just if(string[0]) to check an empty string.

About the arguments, you can get all arguments stacked together with read_args() if you're just going to add all of them like that anyway.

And about less than 4 arguments, you should modify cmd_access()'s 4th argument to 1, that sets the required number of arguments, that's why you can't use less.

fysiks 05-06-2011 21:16

Re: Empty string? How can I check?
 
I think the answer to your question lies here: When using cmd_access() the command itself is considered an argument. If you want it to require 4 arguments be provided by the user with the command then you need to change the 4 to 5.

P.S. What is up with your title? A little misleading :).

Exolent[jNr] 05-06-2011 21:19

Re: Empty string? How can I check?
 
read_argv() returns the number of characters in the string.

Just check if that is 0.

killergirl 05-07-2011 04:42

Re: Empty string? How can I check?
 
My bad, because I post so quickly. I wanted to check if argument 4 is empty. If is empty than the function is returned.

PHP Code:


if(!cmd_access(idlvlcid1))
      return 
PLUGIN_HANDLED

if(argFour[0])
{
   
console_print(index"please use all values !")
}

return 

That is correct?


Edit:

I found the answer !

PHP Code:

if(strlen(argFour) <= 0)
{
   
//this means is empty


Thank you for support !

ConnorMcLeod 05-07-2011 06:07

Re: Empty string? How can I check?
 
read_argv(4, argFour, 31) already returns the length, as xolent already told you.
Please read people answers ;)

fysiks 05-07-2011 13:55

Re: Empty string? How can I check?
 
Why not do this:

PHP Code:

if(!cmd_access(idlvlcid5)) 

It will require the player to use 4 arguments when using the command.

ConnorMcLeod 05-07-2011 14:00

Re: Empty string? How can I check?
 
I think that if you pass "" as argument, it could be counted, not sure though.

Hunter-Digital 05-07-2011 14:16

Re: Empty string? How can I check?
 
Quote:

Originally Posted by ConnorMcLeod (Post 1465125)
I think that if you pass "" as argument, it could be counted, not sure though.

That's true, read_argc() counts "" as argument, I just tested it.

fysiks 05-07-2011 14:28

Re: Empty string? How can I check?
 
Quote:

Originally Posted by ConnorMcLeod (Post 1465125)
I think that if you pass "" as argument, it could be counted, not sure though.

Interesting. So, the questoin then becomes how likely is someone going to do that?

So, every function that uses cmd_access() without checking arg length of all arguments has a potential breaking point :).


All times are GMT -4. The time now is 04:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.