I know this is weird, i'm making a VIP code activation thingy. When i save it, a message pops up in red on the console saying "Error while compiling: test.cs(36,33): error CS1503: Argument `#1' cannot convert `string' expression to type `int'" I don't know how to fix this.
"
This is the part of code i'm getting errors at,
Also, i'm new to all of this, so i don't know what methods to use. Thanks.Code:[ChatCommand("activate")] private void Activate(BasePlayer plr, string command, string[] args) { SendReply(plr, "Trying to activate..."); ---> string secondargs = args[0].ToString(); if (!Codes.Contains(secondargs)) { SendReply(plr, "That code is invalid! Please try again."); } else { rust.RunServerCommand("oxide.usergroup add " + plr.displayName + " vip"); rust.BroadcastChat("Welcome " + plr.displayName + " to the VIP crew!"); SendReply(plr, "Success! Remember, you get a vip kit which you can redeem via /kit vip."); } }
Solved Whats wrong with this code?
Discussion in 'Rust Development' started by ZyKron, Feb 2, 2018.
-
I assume the Codes is List<int>, in which case you have to convert the string secondargs to int by using
Code:int num = int.Parse(secondargs);
Code:int num; if (!int.TryParse(secondargs, out num)) { SendReply(plr, "Invalid number " + secondargs); return; }
-
Thanks so much! I know where i messed up at, i forgot that it was an integer list. Lol, thanks!