Thread
:
How to change string into int?
View Single Post
nosoop
Veteran Member
Join Date: Aug 2014
07-11-2019 , 08:06 Re: How to change string into int?
#
2
Don't put yourself down over it, gotta start somewhere.
The thing that stands out is that you really should indent your code. Take a look at other (released) plugins as examples and see that they indent the line after every opening brace (
{
) and unindent before the closing one (
}
). It'll easily catch the missing bracket at the end that would cause this to not compile, assuming it didn't get lost when making this post.
StringToInt
is used correctly, so you're fine there, and so are the other function calls from what I can tell.
if (args > 2)
doesn't catch the case if you only pass in zero or one argument (something like
/spam r
may throw an error at
GetCmdArg(2, ...)
).
if (iamount = 0)
is also incorrect. The compiler or your development environment will give you a warning about a possibly unintended assignment because of the single equals; equality checks use
==
. You'll want to use
if (iamount <= 0)
to ensure the player doesn't put in a negative value.
You may also want to add one last else to tell the player that they didn't pick a valid color, but I'm sure you'd catch that in a more serious plugin.
You should also use
return
to leave the function early (after you use
ReplyToCommand
, you don't want to process the rest of the function). For console / chat commands,
return Plugin_Handled
is generally the way to go about it.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord --
PM me on the forums
regarding inquiries.
AlliedModders Releases
/
Github
/
TF2 Server
/ Donate (
BTC
/
BCH
/
coffee
)
nosoop
View Public Profile
Send a private message to nosoop
Visit nosoop's homepage!
Find More Posts by nosoop