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.

#26 2017-02-24 10:27:37

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: [Release] EE Bot Code Generator

One question, why do you use 2 as layer? Shouldn't it be 0 and 1?

Offline

#27 2017-02-24 10:43:11

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Release] EE Bot Code Generator

destroyer123 wrote:

Also, there are a large number of people playing EE that want to make a bot, but don't know where to start. This, although most people who are familiar with making bots wouldn't use it, could act as a starting point for new bot makers, to help them understand playerIO.
(Instead of helping people who ask 'my bot isn't working, can you help fix it' with setting up the playerIO myself, I'm just going to send them here from now on //forums.everybodyedits.com/img/smilies/big_smile)

Although I do agree stuff like this would be good for starters, it is very basic, and it'll still be rather hard to continue from something of this size.
It'd be much better they'd use a library like BotBits, as it's aimed for easier programming and most of all: easier reading.

Offline

#28 2017-02-24 14:55:15

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: [Release] EE Bot Code Generator

capasha wrote:

One question, why do you use 2 as layer? Shouldn't it be 0 and 1?

? I don't quite understand.
If you're talking about the initialization fields of the array, I initialize the array like this

World = new uint[2, 1, 1]

because there are 2 layers, 0 and 1, so I have to initialize them.

Offline

#29 2017-02-24 16:29:18

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: [Release] EE Bot Code Generator

ninjasupeatsninja wrote:
capasha wrote:

One question, why do you use 2 as layer? Shouldn't it be 0 and 1?

? I don't quite understand.
If you're talking about the initialization fields of the array, I initialize the array like this

World = new uint[2, 1, 1]

because there are 2 layers, 0 and 1, so I have to initialize them.

I guess I saw wrong code.

Offline

#30 2017-02-24 17:20:08, last edited by Tomahawk (2017-02-24 17:21:02)

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

Re: [Release] EE Bot Code Generator

destroyer123 wrote:

I agree that the code isn't perfect, but I can't see why it would be inefficient...

ninjasupeatsninja wrote:
case "say": {
	Player PlayerExecuting = Players[e.GetInt(0)];
	string Say = e.GetString(1);
	string Command;
        ...

Two strings and a class get created and disposed every single time a player chats.

The code is thrown together without the use of any functions. The key feature of reusable code is compartmentalisation - i.e. if I want to copy all my EE connection code then I put it in a method and copy that across. That way I can write something not dependent on whether I'm making a console bot or windows form or whatever.


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

Offline

#31 2017-02-24 18:35:11

SirJosh3917
Formerly ninjasupeatsninja
From: USA
Joined: 2015-04-05
Posts: 2,095

Re: [Release] EE Bot Code Generator

Tomahawk wrote:
destroyer123 wrote:

I agree that the code isn't perfect, but I can't see why it would be inefficient...

ninjasupeatsninja wrote:
case "say": {
	Player PlayerExecuting = Players[e.GetInt(0)];
	string Say = e.GetString(1);
	string Command;
        ...

Two strings and a class get created and disposed every single time a player chats.

The code is thrown together without the use of any functions. The key feature of reusable code is compartmentalisation - i.e. if I want to copy all my EE connection code then I put it in a method and copy that across. That way I can write something not dependent on whether I'm making a console bot or windows form or whatever.

Where do you recommend for what specific pieces of code that I group in functions?
How should I go about and not make it dispose and get created every single time a player chats?

____
on the sidenote 0.3.0 is out, changelog here

Offline

#32 2017-02-24 19:22:28, last edited by LukeM (2017-02-24 19:28:39)

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

Re: [Release] EE Bot Code Generator

Tomahawk wrote:

Two strings and a class get created and disposed every single time a player chats.

Ok, that could be very slightly more efficient, but it would make next to no difference in speed (unless many thousands of messages were being sent per second).
The class isnt actually initialised there, so it would only be a pointer that was actually created, rather than a class, so there wouldnt be any major memory allocation or anything.

Tomahawk wrote:

The code is thrown together without the use of any functions. The key feature of reusable code is compartmentalisation - i.e. if I want to copy all my EE connection code then I put it in a method and copy that across. That way I can write something not dependent on whether I'm making a console bot or windows form or whatever.

I guess it would be best to move the initialisation code (main void up to read line) and the command code (the switch) to their own method, but other than that I dont think anything else should need it.
Edit: For the initialisation code, you could pass the username / password / worldID to the method, so it was completely independant from the form / console

ninjasupeatsninja wrote:

Where do you recommend for what specific pieces of code that I group in functions?
How should I go about and not make it dispose and get created every single time a player chats?

Look above for what code to put into functions.

Id move the Player PlayerExecuting = Players[e.GetInt(0)]; and string Command; to inside the if( Say.Substring(0, 1) == "!" )

				case "say": {
					string Say = e.GetString(1);
					
					if( Say.Length > 1 ) {
						if( Say.Substring(0, 1) == "!" ) { // ! is the command prefix
							string Command = Say.Substring(1).ToLower();
							Player PlayerExecuting = Players[e.GetInt(0)];
							
							switch(Command) { //Each one of these case "": are commands
								case "help":
								con.Send("say", "[Bot] !help executed!");
								break;
								
								case "download":
								con.Send("say", "[Bot] Download at http://www.sirjosh3917.tk/codegen.html");
								break;
								
								case "name":
								con.Send("say", string.Format("[Bot] Your name is {0}, id is {1}, ConnectId is {2}.", PlayerExecuting.Name, PlayerExecuting.Id, PlayerExecuting.ConnectId));
								break;
							}
						}
					}
				}
				break;

If you wanted to put it into a method: 
				case "say": {
					string Say = e.GetString(1);
					
					if( Say.Length > 1 ) {
						if( Say.Substring(0, 1) == "!" ) { // ! is the command prefix
							CommandSent(Players[e.GetInt(0)], Say.Substring(1).ToLower());
						}
					}
				}
				break;

This would mean that command and player are only used when the player actually says a command, rather than whenever anyone says a non-command message

Offline

#33 2017-02-25 09:10:54

capasha
Member
Joined: 2015-02-21
Posts: 4,066

Re: [Release] EE Bot Code Generator

destroyer123 wrote:
Tomahawk wrote:

Two strings and a class get created and disposed every single time a player chats.

Ok, that could be very slightly more efficient, but it would make next to no difference in speed (unless many thousands of messages were being sent per second).
The class isnt actually initialised there, so it would only be a pointer that was actually created, rather than a class, so there wouldnt be any major memory allocation or anything.

Tomahawk wrote:

The code is thrown together without the use of any functions. The key feature of reusable code is compartmentalisation - i.e. if I want to copy all my EE connection code then I put it in a method and copy that across. That way I can write something not dependent on whether I'm making a console bot or windows form or whatever.

I guess it would be best to move the initialisation code (main void up to read line) and the command code (the switch) to their own method, but other than that I dont think anything else should need it.
Edit: For the initialisation code, you could pass the username / password / worldID to the method, so it was completely independant from the form / console

ninjasupeatsninja wrote:

Where do you recommend for what specific pieces of code that I group in functions?
How should I go about and not make it dispose and get created every single time a player chats?

Look above for what code to put into functions.

Id move the Player PlayerExecuting = Players[e.GetInt(0)]; and string Command; to inside the if( Say.Substring(0, 1) == "!" )

				case "say": {
					string Say = e.GetString(1);
					
					if( Say.Length > 1 ) {
						if( Say.Substring(0, 1) == "!" ) { // ! is the command prefix
							string Command = Say.Substring(1).ToLower();
							Player PlayerExecuting = Players[e.GetInt(0)];
							
							switch(Command) { //Each one of these case "": are commands
								case "help":
								con.Send("say", "[Bot] !help executed!");
								break;
								
								case "download":
								con.Send("say", "[Bot] Download at http://www.sirjosh3917.tk/codegen.html");
								break;
								
								case "name":
								con.Send("say", string.Format("[Bot] Your name is {0}, id is {1}, ConnectId is {2}.", PlayerExecuting.Name, PlayerExecuting.Id, PlayerExecuting.ConnectId));
								break;
							}
						}
					}
				}
				break;

If you wanted to put it into a method: 
				case "say": {
					string Say = e.GetString(1);
					
					if( Say.Length > 1 ) {
						if( Say.Substring(0, 1) == "!" ) { // ! is the command prefix
							CommandSent(Players[e.GetInt(0)], Say.Substring(1).ToLower());
						}
					}
				}
				break;

This would mean that command and player are only used when the player actually says a command, rather than whenever anyone says a non-command message

Maybe this one is better, but that's how I use on command bots, http://pastebin.com/N9mf6SDV

Offline

#34 2017-02-25 11:59:24, last edited by LukeM (2017-02-25 12:05:47)

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

Re: [Release] EE Bot Code Generator

capasha wrote:

Maybe this one is better, but that's how I use on command bots, http://pastebin.com/N9mf6SDV

That is similar to how I do it too, but I thought it might be a bit confusing for newer people. Maybe add another checkbox, for advanced commands or something, which replaces this bit:

too many indents to fit in the code box thing, so I removed them

string[] Command = Say.Substring(1).ToLower().Split(' ');
Player PlayerExecuting = Players[e.GetInt(0)];

switch(Command[0]) { //Each one of these case "": are commands

Then you could, inside each case, use the other parameters in the command

Offline

Wooted by:
LukeM1488020364648815

Board footer

Powered by FluxBB

[ Started around 1711656185.2571 - Generated in 0.101 seconds, 10 queries executed - Memory usage: 1.56 MiB (Peak: 1.73 MiB) ]