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 14:59:01

Anatoly
Guest

CoinBot crashes

I don't think I need to show you all the code

static void Coin() {
	while(true) {
		Thread.Sleep(1);
		con.Send("b", 1, 1, 22, 100);
	}
}

while(true) makes the loop infinite, i checked that.

If Thread.Sleep is 17, the Bot crashes, with low values till ~5 he doesn't crash, but doesn't place coin, in some other ways he places the coin then crashes instead of replacing the coin again and again...

#2 2017-04-11 15:28:25, last edited by LukeM (2017-04-11 18:46:55)

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

Re: CoinBot crashes

Where in your code is this? If its inside a playerIO message, then I think its because it stops the thread from running

Just a quick explanation:

The average bot has 2 threads (at least 2 that you need to worry about), which are basically points in the program being run
One is the main one, which enters the program in the Main void
The other is used by PlayerIO

The PlayerIO cant have anything in it that takes a long period of time, otherwise nothing else can happen in it, so it disconnects

If you really want it to work like this, you have a few options:
Add a timer, which fires every few milliseconds
Run this code on a new thread

Here is an example for the new thread (the easiest):

static void Coin() {
	new Thread(() => 
	{
		while(true) {
			Thread.Sleep(1);
			con.Send("b", 1, 1, 22, 100);
		}
	}).Start();
}

you also need "using System.Threading;" at the top

Also, a quick note:
There isnt a major difference between sleep 1 and sleep 10 in most computers, the smallest possible sleep is around 15 ms
There are a few exceptions, but in most cases, there is no difference below 5

Offline

Wooted by:

#3 2017-04-11 16:29:42

Anatoly
Guest

Re: CoinBot crashes

This is another bot

#4 2017-04-11 17:06:52, last edited by Processor (2017-04-11 17:08:53)

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: CoinBot crashes

Level owners no longer have a message limit, so it is possible to "crash" your own word now. //forums.everybodyedits.com/img/smilies/tongue

destroyer123 wrote:

There isnt a major difference between sleep 1 and sleep 10 in most computers, the smallest possible sleep is around 15 ms
There are a few exceptions, but in most cases, there is no difference below 5

This is only true for laptops and other battery powered machines. Even then, it is possible to reduce the timer resolution by using the WinAPI. (Or you know, open a youtube video and that video will reduce the timer resolution for you since it is a system wide setting!)


I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.

Offline

#5 2017-04-11 17:09:37, last edited by LukeM (2017-04-11 18:40:18)

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

Re: CoinBot crashes

Processor wrote:

Level owners no longer have a message limit, so it is possible to "crash" your own word now. //forums.everybodyedits.com/img/smilies/tongue

With an interval of 17, it shouldnt crash though...
Im guessing that it is blocking the PlayerIO thread, so it cant send / recieve / process messages

Processor wrote:

This is only true for laptops and other battery powered machines. Even then, it is possible to reduce the timer resolution by using the WinAPI. (Or you know, open a youtube video and that video will reduce the timer resolution for you since it is a system wide setting!)

It's been the case for every computer I've tested (3 desktop PCs and a laptop)
Also, I thought Google (and a few other companies) removed the increase in resolution from most of their programs a while ago

Offline

LukeM1491926977654318

Board footer

Powered by FluxBB

[ Started around 1732716541.5702 - Generated in 0.323 seconds, 12 queries executed - Memory usage: 1.39 MiB (Peak: 1.5 MiB) ]