Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2017-04-11 09:02:56

Anatoly
Guest

My commands are required to have a second argument

				if (arg[0] == "!c") {
					con.Send("say", "/pm " + Players[m.GetInt(0)].Username + " You have got " + Players[m.GetInt(0)].Coins + " coins!");
				}

!c - Returns nothing
!c blablabla - Returns right thing.

#2 2017-04-11 09:58:02

MartenM
Member
From: The Netherlands
Joined: 2016-03-31
Posts: 978
Website

Re: My commands are required to have a second argument

So where does the code stop? Have you tried adding break points to see if the code will even run at all?


lm3hgg8.jpg

Ingame: marten22        My steam: MartenM

Offline

Wooted by: (4)

#3 2017-04-11 10:32:06, last edited by LukeM (2017-04-11 10:32:59)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: My commands are required to have a second argument

Could you give us the rest of the message code? There isnt much we can do from just that

Offline

Wooted by: (4)

#4 2017-04-11 11:07:14

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,847

Re: My commands are required to have a second argument

If arg is storing the contents of a string split, the error is somewhere else. That code is fine.


One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.

Offline

#5 2017-04-11 14:56:17

Anatoly
Guest

Re: My commands are required to have a second argument

CONTENT WARNING

#6 2017-04-11 15:15:50, last edited by LukeM (2017-04-11 15:16:30)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: My commands are required to have a second argument

The problem is that when you only have one argument, the earlier commands crash when you try to get the second argument, which means the message isnt sent

Before anything that uses arg[1 or more], check that arg.Length > the number
e.g:

				if ((Players[m.GetInt(0)].Rank == 4 || Players[m.GetInt(0)].Rank == 5) && arg.Length > 1) {
					// Which player is now edited?
					string user = arg[1];
					int editing = 0;

					foreach(KeyValuePair<int,Player> p in Players)
					{
						if (p.Value.Username == user)
						{
							editing = p.Value.Id;
							break;
						}
					}

					// Commands
					if (arg[0] == "!givecoins" && arg.Length > 2) {
						int x = Int32.Parse(arg[2]);
						Players[editing].Coins = Players[editing].Coins + x;
					}
				}

Also, just to make it a bit neater, you could also do this:

if (Players[m.GetInt(0)].Rank >= 3) {

instead of

if (Players[m.GetInt(0)].Rank == 3 || Players[m.GetInt(0)].Rank == 4 || Players[m.GetInt(0)].Rank == 5) {

Offline

#7 2017-04-11 16:14:35

N1KF
Wiki Mod
From: ဪဪဪဪဪ From: ဪဪဪဪဪ From: ဪဪဪဪဪ
Joined: 2015-02-15
Posts: 11,113
Website

Re: My commands are required to have a second argument

AnatolyEE wrote:
CONTENT WARNING

Why does this post have a trigger warning?

Offline

#8 2017-04-11 16:36:38

Anatoly
Guest

Re: My commands are required to have a second argument

N1KF wrote:
AnatolyEE wrote:
CONTENT WARNING

Why does this post have a trigger warning?

Because Diff added it //forums.everybodyedits.com/img/smilies/wink

#9 2017-04-11 16:49:21

kubapolish
Banned
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-19
Posts: 1,024
Website

Re: My commands are required to have a second argument

N1KF wrote:
AnatolyEE wrote:
CONTENT WARNING

Why does this post have a trigger warning?

i think it's because of spaghetti code


Offline

Wooted by:

#10 2017-04-11 17:11:42

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: My commands are required to have a second argument

kubapolish wrote:
N1KF wrote:
AnatolyEE wrote:
CONTENT WARNING

Why does this post have a trigger warning?

i think it's because of spaghetti code

Its actually not too bad (well at least not as bad as most other bots)

Offline

Wooted by:
LukeM1491927102654319

Board footer

Powered by FluxBB

[ Started around 1732394160.5541 - Generated in 0.225 seconds, 13 queries executed - Memory usage: 1.64 MiB (Peak: 1.88 MiB) ]