AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   arguments - whats wrong ? (https://forums.alliedmods.net/showthread.php?t=6949)

MC-Olivenoel 10-20-2004 04:49

arguments - whats wrong ?
 
Hi

need help with the arguments of a command

first...

****** ****ing arguments ******* ******. this *************** small is n ************ language. ****** :evil:

ok now lets have a look at the problem :wink:



(its n test script....)
Code:
#include <amxmod> #include <amxmisc>   public plugin_init() {  register_plugin("test","073","MC-Olivenoel")  register_clcmd("make_test","maketest",0,"make the test")   } public maketest(id) { new varil0 if (read_argc() == 0) {     //no argument ...     console_print(id,"- no argument = same as make_test 0")     varil0 = 0     return PLUGIN_HANDLED }else{ read_argv(1,varil0,3)   //here is the ************* error ?? } if (varil0 == 0){ //varil0 is 0     client_cmd(id,"say varil0 is 0") return PLUGIN_HANDLED } if (varil0 == 1){ //varil0 is 0     client_cmd(id,"say varil0 is 1") return PLUGIN_HANDLED } if (varil0 == 10){ //varil0 is 0     client_cmd(id,"say varil0 is 10") return PLUGIN_HANDLED } if (varil0 == 200){ //varil0 is 0     client_cmd(id,"say varil0 is 200") return PLUGIN_HANDLED } // here if the argument is wrong     client_cmd(id,"say varil0 is not 0,1,10 or 200")         return PLUGIN_HANDLED }

ok there are lottttts of errors :cry:

Code:

(22) : error 035: argument type mismatch (argument 1)
(29) : warning 217: loose indentation
(35) : warning 217: loose indentation
(41) : warning 217: loose indentation
(47) : warning 217: loose indentation
(52) : warning 217: loose indentation
(54) : warning 217: loose indentation

i want that it works... if i make consol commands

make_test
make_test 0
make_test 1
make_test 10
make_test 20
make_test 100
make_test 200
make_test 1000

can someon tell me how to use the "read_argv" in correckt way _??

cucu

Da Bishop 10-20-2004 06:51

try this

Code:
#include <amxmod> #include <amxmisc> #define textlength 192 #pragma tabsize 0 public plugin_init() { register_plugin("test","073","MC-Olivenoel") register_clcmd("make_test","maketest",0,"make the test") } public maketest(id) { new varil[textlength+1] read_argv(1,varil,textlength) if (varil[0] == "0"){ //varil is 0     client_cmd(id,"say varil is 0") return PLUGIN_HANDLED } if (varil[0] == "1"){ //varil is 0     client_cmd(id,"say varil is 1") return PLUGIN_HANDLED } if (varil[0] == "10"){ //varil is 0     client_cmd(id,"say varil is 10") return PLUGIN_HANDLED } if (varil[0] == "200"){ //varil is 0     client_cmd(id,"say varil is 200") return PLUGIN_HANDLED } else {     client_cmd(id,"say varil is not 0,1,10 or 200") }       return PLUGIN_HANDLED }

DS 10-20-2004 07:14

Almost correct, Da Bishop. When checking for 0 or 1, those would need to be single quotes, I believe. Also the checking for 10 or 100 would never work because all you're doing is comparing the first char of the string to "10". Heh, how can one character be the same as "10". That's not going to work.

I would recommend creating a new variable and turning that argument string into a number. Checking it for some value will be much easier that way, I think.

Code:
#include <amxmod> #include <amxmisc> #define textlength 192 #pragma tabsize 0 public plugin_init() { register_plugin("test","073","MC-Olivenoel") register_clcmd("make_test","maketest",0,"make the test") } public maketest(id) { new varil[textlength+1] read_argv(1,varil,textlength) new numvar = str_to_num(varil) if (numvar == 0){ //numvar is 0     client_cmd(id,"say numvar is 0") return PLUGIN_HANDLED } if (numvar == 1){ //numvar is 1     client_cmd(id,"say numvar is 1") return PLUGIN_HANDLED } if (numvar == 10){ //numvar is 10     client_cmd(id,"say numvar is 10") return PLUGIN_HANDLED } if (numvar == 200){ //numvar is 200     client_cmd(id,"say numvar is 200") return PLUGIN_HANDLED } else {     client_cmd(id,"say numvar is not 0,1,10 or 200") }       return PLUGIN_HANDLED }

MC-Olivenoel 10-20-2004 07:37

ok nice ... :)

but if i change str to num

a=1
b=2
c=4
d=8

ok and so on.....

in the if part.....
"0" is there also n string so i must change it also in an nummer it will by something like 4000 or mor 8)

is it posible to make (to find the string easyr)

Code:
if (numvar == str_to_num("0")){ //numvar is 0     client_cmd(id,"say numvar is 0") return PLUGIN_HANDLED }

is this right or wrong ???

MC-Olivenoel 10-20-2004 08:27

ok i make new post ;) find some new way ... much easyr


Code:
#include <amxmod> #include <amxmisc> #define textlength 50 #pragma tabsize 0 public plugin_init() { register_plugin("test","073","MC-Olivenoel") register_clcmd("make_test","maketest",0,"make the test") } public maketest(id) { new StringList[9][] = {"0","1","10","200","test0", "test1", "test2", "test10", "test200"} new varil[textlength+1] read_argv(1,varil,textlength) if (equali(StringList[0], varil)){ //numvar is 0     client_cmd(id,"say numvar is 0") return PLUGIN_HANDLED } if (equali(StringList[1], varil)){ //numvar is 1     client_cmd(id,"say numvar is 1") return PLUGIN_HANDLED } if (equali(StringList[2], varil)){ //numvar is 10     client_cmd(id,"say numvar is 10") return PLUGIN_HANDLED } if (equali(StringList[3], varil)){ //numvar is 200     client_cmd(id,"say numvar is 200") return PLUGIN_HANDLED } client_cmd(id,"say numvar is not 0,1,10 or 200")       return PLUGIN_HANDLED }

0 ERRORS
ok i will test it in the evening of it works in HL ;)

some litle thing ...
Code:

#pragma tabsize 0
whats this ??

cucu

DS 10-20-2004 09:03

Looks like it should run okay.

Code:
#pragma tabsize 0

That tells the compiler to stop issuing the loose indentation warning. You usually get that warning when your code indenting isn't lined up correctly. That's why you got those warnings that you posted in your original message. It's really nothing to worry about if you do get the warning because your plugin should still run, but setting the tabsize to 0 just prevents the warning from coming up.

Da Bishop 10-20-2004 14:49

sry, i always throw #pragma tabsize 0 in my code. I hate those stupid indentation errors - make no sense - too lazy to really go back and check my line up. Not going to cause problems anyways.


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

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