AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   a minor question about read_argc() (https://forums.alliedmods.net/showthread.php?t=6461)

breaddawson 10-03-2004 04:39

a minor question about read_argc()
 
yes, i read the sticky tutorial

Code:
if (read_argc() == 0) {     console_print(id,"[AMXX] You must specify a user")     return PLUGIN_HANDLED }

Quote:

read_argc() returns the number of arguments after the command. If there are no arguments, then it prints "[AMXX] You must specify a user", and we stop code execution.
i tried that before,but it didn't work then
it is to say that when u type a single command without any argument
amx x still won't tell u "u must specify a user"
i thought it might be a small error
so i didn't care about it

but just at yesterday i modified a place
it was

Code:
read_argc() == 0

i changed it to

Code:
read_argc() == 1

then it works well
when u typed a single command without any argument
amx x will remind u to add one

then i'm puzzled :?:
why "0" doesn't work?

Greenberet 10-03-2004 05:58

cause the wirst arg is the name of the cmd
e.g.

amx_help 14

there are 2 arguments

breaddawson 10-03-2004 07:20

:) thank u for ur reply
i know that now
so,as what u said,the script i copied from the tutorial is wrong
is it??

and the id of the first argument must be 0 ,is it?
i said this because i found another block in the tutorial

Code:
read_argv(1,user,32)

Quote:

With this command, we get the first argument of the command, and put it into the user variable. The maximum length of the argument that we would get is 32 characters.
and as what u said ,the "first" here should be "second"

am i right??

:wink: thank u again~~

xeroblood 10-03-2004 11:36

0 represents the First argument,
1 represents the second argument,
2 represents the third argument,
etc etc...

Basically it is like the indexing of arrays...

amx_slap someone 100

Arg_0 = amx_slap
Arg_1 = someone
Arg_2 = 100

read_argc() = 3

I hope that helps!

breaddawson 10-03-2004 11:49

xeroblood,thank u very much :)

maybe devicenull should modify his sticky tutorial
:wink:


All times are GMT -4. The time now is 17:22.

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