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-04-01 20:31:30

MikeK
Member
From: Earth
Joined: 2015-03-13
Posts: 25

[Question] Another dumb question

So, I'm trying to make meteor using this code (worldh is world height):

if (b == 204)
{
 for (int i = 0; i < worldh - y; ++i)
  {
   con.Send(editkey, 0, x, y + i + 1, 203);
   Thread.Sleep(10);
   con.Send(editkey, 0, x, y + i, 368);
   Thread.Sleep(10);
   con.Send(editkey, 0, x, y + i, 0);
   Thread.Sleep(10);
  }//for
}//if

I thought it works properly... until i placed more than 1 meteors.
The question is: how to make many meteors fall at the same time?


FluxBB bbcode test

Offline

#2 2015-04-01 20:46:08

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

Re: [Question] Another dumb question

You can do this by multithreading.
Tutorial: https://www.youtube.com/watch?v=8mjqXiggWNc


vF0MA5o.png

Offline

#3 2015-04-01 21:02:57

MikeK
Member
From: Earth
Joined: 2015-03-13
Posts: 25

Re: [Question] Another dumb question

Hmm.. Are there any ways to multithread in console application?


FluxBB bbcode test

Offline

#4 2015-04-01 21:36:05

ewoke
Member
Joined: 2015-02-20
Posts: 412

Re: [Question] Another dumb question

yup basicly the same as in a windows form


if you can read this....good for you

Offline

#5 2015-04-01 22:27:31, last edited by Mylo (2015-04-01 22:38:34)

Mylo
Master Developer
From: Drama
Joined: 2015-02-15
Posts: 829

Re: [Question] Another dumb question

async tasks might be a possible solution, too..

//TODO implement b, x, y, worldh etc.
static void Main(){
  Meteor();
  Meteor();
}
 static async void Meteor(){
  if (b == 204){
    for (int i = 0; i < worldh - y; ++i){
      con.Send(editkey, 0, x, y + i + 1, 203);
      await Task.Delay(10);
      con.Send(editkey, 0, x, y + i, 368);
      await Task.Delay(10);
      con.Send(editkey, 0, x, y + i, 0);
      await Task.Delay(10);
    }//for
  }//if
}

Note: I code in Vb.NET - can't gurantee this is even working and doing what you want..

Offline

#6 2015-04-06 12:09:41

DarkDragon4900
Member
Joined: 2015-03-17
Posts: 251

Re: [Question] Another dumb question

async & await Should do fine.
Though, you can try using

ThreadPool.QueueUserWorkItem(delegate{/*Do stuff.*/});

// Unless it's in a void, at which case you'd want to replace the delegate with the void's name.

ThreadPool.QueueUserWorkItem(Meteor());

It's best to use async & await though, unless you have an old visual studio.
So mylo's code would do it.

Offline

DarkDragon49001428318581491493

Board footer

Powered by FluxBB

[ Started around 1732680866.4478 - Generated in 0.037 seconds, 13 queries executed - Memory usage: 1.45 MiB (Peak: 1.57 MiB) ]