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 2015-02-24 01:47:13

AK712
Member
Joined: 2015-02-16
Posts: 94

Concerning System.Threading.Thread.Sleep()

Hello everyone!

I am having trouble with a bot that needs to /teleport multiple people with breaks in between. For example, code is something like this:

connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 11 14");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 11 14");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 13 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 17 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 17 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 13 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 11 14");

Unfortunately, it seems only one person can be /teleported at a time. I think it has something to do with the System.Threading command not letting any other commands pass during it. Can anyone help me, so everyone can teleport while others are teleporting?

Thanks,
AK712


O4DmNuI.png

Offline

#2 2015-02-24 02:51:04

BuzzerBee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,570

Re: Concerning System.Threading.Thread.Sleep()

Just wondering... Why don't you just delete the Thread.Sleep()?


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#3 2015-02-24 03:57:31

AK712
Member
Joined: 2015-02-16
Posts: 94

Re: Concerning System.Threading.Thread.Sleep()

Because they need to stay in that teleported area for a specific amount of time.


O4DmNuI.png

Offline

#4 2015-02-24 04:11:40, last edited by Xfrogman43 (2015-02-24 04:12:22)

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: Concerning System.Threading.Thread.Sleep()

ThreadPool.QueueUserWorkItem(delegate
{
          //Your Code Here
});


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#5 2015-02-24 09:06:41

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: Concerning System.Threading.Thread.Sleep()

BuzzerBee wrote:

Just wondering... Why don't you just delete the Thread.Sleep()?

Because the new EE server being developed by the new admins doesn't allow a lot of messages in chat for a time of 575 at minimum. Altough, some server code will remain and still remains.


Try changing it to something like:
Sleep(575);
//code
Sleep(400);
//code
Sleep(575);
//code

Hope you get it. Works extremely fine for me.


http://i.imgur.com/bjvgH5L.png?1

Offline

#6 2015-02-24 09:07:54

realmaster42
Formerly marcoantonimsantos
From: ̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍̍
Joined: 2015-02-20
Posts: 1,380
Website

Re: Concerning System.Threading.Thread.Sleep()

AK712 wrote:

Hello everyone!

I am having trouble with a bot that needs to /teleport multiple people with breaks in between. For example, code is something like this:

connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 11 14");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 11 14");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 13 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 17 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 17 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 13 16");
System.Threading.Thread.Sleep(400);
connection.Send("say", "/teleport " + users[m.GetInt(0)].username + " 11 14");

Unfortunately, it seems only one person can be /teleported at a time. I think it has something to do with the System.Threading command not letting any other commands pass during it. Can anyone help me, so everyone can teleport while others are teleporting?

Thanks,
AK712

Are you using a loop? (for (..., while (...)


http://i.imgur.com/bjvgH5L.png?1

Offline

#7 2015-02-24 12:50:44

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,645

Re: Concerning System.Threading.Thread.Sleep()

I think he wants to say that the bot dosent process any other event until the action of this one is done.


Everybody edits, but some edit more than others

Offline

#8 2015-02-24 17:09:37

912468
Member
Joined: 2015-02-21
Posts: 212
Website

Re: Concerning System.Threading.Thread.Sleep()

You can do this by multithreading (Look here for tutorial). This will allow multiple players at the same time.


vF0MA5o.png

Offline

#9 2015-02-24 17:20:53

goeyfun
Member
From: Mighty Japan
Joined: 2015-02-18
Posts: 667

Re: Concerning System.Threading.Thread.Sleep()

async <3 <3 I gotta go through the basics of c#, miss out some of them :\


Ug3JzgO.png

Offline

#10 2015-02-26 06:13:23

Kaslai
Official Caroler
From: SEAͩT̓͑TLͯͥͧͪ̽ͧE͑̚
Joined: 2015-02-17
Posts: 787

Re: Concerning System.Threading.Thread.Sleep()

All you need is a message queue and a stopwatch to determine when a certain amount of time has passed.

Offline

#11 2015-03-02 21:43:28

madiik
Member
From: floor above Yuuta
Joined: 2015-02-26
Posts: 514

Re: Concerning System.Threading.Thread.Sleep()

Sleep is tottaly not reccomended, I would reccomend async, like goeyfun said.

await Task.Delay(int milliseconds)

//forums.everybodyedits.com/img/smilies/tongue


shh i have returned

Offline

madiik1425329008478513

Board footer

Powered by FluxBB

[ Started around 1714944097.309 - Generated in 0.060 seconds, 12 queries executed - Memory usage: 1.54 MiB (Peak: 1.71 MiB) ]