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 2016-07-30 11:15:42

Uptight_actor
Anonymous user

[Question] Replacing Blocks?

Im currently making a bot. But the problem is I need to manually replace the blocks since I don't know how to make a replace command.
Any help would be nice.

#2 2016-07-30 11:48:37

australian_abyss
Anonymous user

Re: [Question] Replacing Blocks?

save the blocks from init, reset and added blocks
Then you can do a for loop through x and y, and search if the id you want to replace exists.
Then send the message with the block information to replace. The best way would be to thread the function there you have the for loop.

#3 2016-07-30 14:03:52

stony_Capitalist
Anonymous user

Re: [Question] Replacing Blocks?

australian_abyss wrote:

save the blocks from init, reset and added blocks
Then you can do a for loop through x and y, and search if the id you want to replace exists.
Then send the message with the block information to replace. The best way would be to thread the function there you have the for loop.

You may wish to use Processor's InitParse to do that //forums.everybodyedits.com/img/smilies/wink

#4 2016-07-30 14:39:04

Sauerkraut40
Anonymous user

Re: [Question] Replacing Blocks?

Threading is the easy way. If you manage to figure out a timer, even better.

Folks, how should we do that? I could see having the tick simply do the search for the ID over again until none left. Should it be that way, or should it find them all once, record those in a collection, and tick them off?

They have slightly different results, but what's the 'better' approach (something I haven't thought of?)

#5 2016-07-30 18:06:44, last edited by Australian_Axe (2016-07-30 18:16:59)

Australian_Axe
Anonymous user

Re: [Question] Replacing Blocks?

Sauerkraut40 wrote:

Threading is the easy way. If you manage to figure out a timer, even better.

Folks, how should we do that? I could see having the tick simply do the search for the ID over again until none left. Should it be that way, or should it find them all once, record those in a collection, and tick them off?

They have slightly different results, but what's the 'better' approach (something I haven't thought of?)

Depends. Can the room change while you're replacing stuff?
Why am I asking?
Imagine you'd first gather everything in a collection and then tick them off from that.
What if somebody removes one of the blocks in your list? Then you'll replace one faulty or do a replace that has actually no effect.
By searching for (a single (performance)) block every "tick", you will eliminate those problems, you'd have to think of a way to replace blocks at random though, in case that matters (doesn't look very pretty when you start from the top and then slowly work down instead of replacing blocks "randomly").

Off-topic edit: Loving my avi.

Edit edit: I don't know why I didn't post as den3107.

#6 2016-07-30 18:15:26, last edited by useful_undertaker (2016-07-30 18:16:05)

useful_undertaker
Anonymous user

Re: [Question] Replacing Blocks?

Australian_Axe wrote:
Sauerkraut40 wrote:

Threading is the easy way. If you manage to figure out a timer, even better.

Folks, how should we do that? I could see having the tick simply do the search for the ID over again until none left. Should it be that way, or should it find them all once, record those in a collection, and tick them off?

They have slightly different results, but what's the 'better' approach (something I haven't thought of?)

Depends. Can the room change while you're replacing stuff?
Why am I asking?
Imagine you'd first gather everything in a collection and then tick them off from that.
What if somebody removes one of the blocks in your list? Then you'll replace one faulty or do a replace that has actually no effect.
By searching for (a single (performance)) block every "tick", you will eliminate those problems, you'd have to think of a way to replace blocks at random though, in case that matters (doesn't look very pretty when you start from the top and then slowly work down instead of replacing blocks "randomly").

Off-topic edit: Loving my avi.

The way I deal with room changes is listening for "b" messages
If a block is placed, a "b" message is generated with all the information you need to update your worldBlockDictionary (or whatever other storage ADT you decided to use)

#7 2016-07-30 18:15:29, last edited by QueenQuake (2016-08-01 15:28:39)

QueenQuake
Anonymous user

Re: [Question] Replacing Blocks?

Sauerkraut40 wrote:

Threading is the easy way. If you manage to figure out a timer, even better.

Folks, how should we do that? I could see having the tick simply do the search for the ID over again until none left. Should it be that way, or should it find them all once, record those in a collection, and tick them off?

They have slightly different results, but what's the 'better' approach (something I haven't thought of?)

Add blocks to a list from all threads,
have 1 thread that uses foreach on the list that keeps going around and around delegating each block to a bot (can be used with multiple bots in the same world - that's what I use it for) - optional timer (I have mine set to 1 with 6 bots on a server - will need to experiment)
when a block placement message has been received - remove the item matching it from the list. Edit: you can use https://forums.everybodyedits.com/viewt … p?id=35726 and trigger when your world blocks array is changed.

You will now have a system that will have flawless block placement.

#8 2016-07-30 19:00:49

Lawful_lecher
Anonymous user

Re: [Question] Replacing Blocks?

Ugh, why are these topics anon...
Just annoys me.

Wooted by: (2)

#9 2016-07-30 19:24:15

Australian_Axe
Anonymous user

Re: [Question] Replacing Blocks?

Lawful_lecher wrote:

Ugh, why are these topics anon...
Just annoys me.

For a beginning programmer this is a little bit legit question.
It's also a bit harder to think of what to google for, since you have to pull it up into an abstracter level, which for many people isn't very easy.
Many other questions indeed are a bit annoying though as those are much more generic.

~Den3107

#10 2016-07-30 23:12:18

KindKidnapper
Anonymous user

Re: [Question] Replacing Blocks?

Australian_Axe wrote:
Lawful_lecher wrote:

Ugh, why are these topics anon...
Just annoys me.

For a beginning programmer this is a little bit legit question.
It's also a bit harder to think of what to google for, since you have to pull it up into an abstracter level, which for many people isn't very easy.
Many other questions indeed are a bit annoying though as those are much more generic.

~Den3107

they didn't ask why they were asking this. They were asking why they set it to anonymous.

Wooted by:

#11 2016-07-31 01:33:18

Sauerkraut40
Anonymous user

Re: [Question] Replacing Blocks?

QueenQuake wrote:
Sauerkraut40 wrote:

Threading is the easy way. If you manage to figure out a timer, even better.

Folks, how should we do that? I could see having the tick simply do the search for the ID over again until none left. Should it be that way, or should it find them all once, record those in a collection, and tick them off?

They have slightly different results, but what's the 'better' approach (something I haven't thought of?)

Add blocks to a list from all threads,
have 1 thread that uses foreach on the list that keeps going around and around delegating each block to a bot (can be used with multiple bots in the same world - that's what I use it for) - optional timer (I have mine set to 1 with 6 bots on a server - will need to experiment)
when a block placement message has been received - remove the item matching it from the list. Edit: you can use https://forums.everybodyedits.com/viewt … p?id=35726 and trigger when your world blocks array is changed.

You will now have a system that will have flawless block placement.

-Koya

I, too, usually use dedicated threads. However, we've discussed (and referred to 1337 legit stackkoverflow pages) how taking a thread and tying it up with Thread.Sleep is a no-go.

So I figure we could discuss the "best practice" even though it doesn't apply to me...

#12 2016-07-31 11:34:37

Corny-cyclist
Anonymous user

Re: [Question] Replacing Blocks?

Theres no shame in asking questions why is this anon?

Wooted by: (4)

#13 2016-07-31 16:04:35

Terrible_tamale
Anonymous user

Re: [Question] Replacing Blocks?

Corny-cyclist wrote:

Theres no shame in asking questions why is this anon?

He might be the one who said that he was going to do anon and maybe reveal himself later. But that's just a guess
-fr0g

#14 2016-08-01 02:37:31

AngryAnt
Anonymous user

Re: [Question] Replacing Blocks?

You could also use botbits to loop through each block and check the id.

#15 2016-08-01 11:24:01

Lawful_lecher
Anonymous user

Re: [Question] Replacing Blocks?

weird witch wrote:

You could also use botbits to loop through each block and check the id.

Am I the only one that refuses to use botbits?

(it was suggested when I started making EE bots)

#16 2016-08-01 13:58:40

Australian_Axe
Anonymous user

Re: [Question] Replacing Blocks?

Lawful_lecher wrote:
weird witch wrote:

You could also use botbits to loop through each block and check the id.

Am I the only one that refuses to use botbits?

(it was suggested when I started making EE bots)

Nah, I make as much as I can myself. Obviously I do use EEPhysics though (when needed).
~den3107

Wooted by:

#17 2016-08-01 16:07:04

Terrible_tamale
Anonymous user

Re: [Question] Replacing Blocks?

Lawful_lecher wrote:
weird witch wrote:

You could also use botbits to loop through each block and check the id.

Am I the only one that refuses to use botbits?

(it was suggested when I started making EE bots)

I don't use botbits. I tried it and I didn't think it was very "noob-friendly"

#18 2016-08-01 17:03:04

australian_abyss
Anonymous user

Re: [Question] Replacing Blocks?

I don't see a reason to have this topic opened. Everyone have written how to make it.
Maybe the owner want to be spoon feeded.

Wooted by:

#19 2016-08-01 21:27:00

Neat-noodle
Anonymous user

Re: [Question] Replacing Blocks?

You could get faster replacing (after more initial processing) by saving all block positions in a Dictionary<int, List<Point>> with the block ID as the key.
~ Tomatohawk

Wooted by:

#20 2016-08-02 15:04:05, last edited by useful_undertaker (2020-05-24 17:22:33)

useful_undertaker
Anonymous user

Re: [Question] Replacing Blocks?

Neat-noodle wrote:

You could get faster replacing (after more initial processing) by saving all block positions in a Dictionary<int, List<Point>> with the block ID as the key.
~ Tomatohawk

Strangely enough I'd do it the other way round,

Dictionary<Point, Block> blockData = new Dictionary<Point, Block>();

where:

Point's overriden EQUALS is defined in terms of (this.x == that.x && this.y == that.y)

Block is a structure containing, among others, a field with int id.


EDIT:
Pros of your method: Faster replacement of all the blocks of one kind
Cons: No clear picture of the whole Block Data in the world

#21 2016-08-02 16:36:27

Sauerkraut40
Anonymous user

Re: [Question] Replacing Blocks?

hey on that note
-- oh tomatohawk I hadn't considered that. The setup there allows for multiple replace things at once. useful (right?)

I'm not sure if this is offtopic. If all we want to do is check off a list of blocks to swap, without needing to really "Key" anything, is there any considerable benefit by using List<Tuple<2 values>> over Dictionary<Key, value>? I figure there'd be something said for not processing keys in the List, but perhaps we never get to that limit

#22 2016-08-02 17:33:26, last edited by stony_Capitalist (2016-08-02 17:47:59)

stony_Capitalist
Anonymous user

Re: [Question] Replacing Blocks?

Neat-noodle wrote:

You could get faster replacing (after more initial processing) by saving all block positions in a Dictionary<int, List<Point>> with the block ID as the key.
~ Tomatohawk

My main problem with that it's unnecessary.

Dictionary<int, List<Point>> Dict1 = new Dictionary<int, List<Point>>();
foreach (KeyValuePair kv in Dict1) {
    foreach (Point p in kv.Value) {
        //send kv.Key to {p.X, p.Y}
    }
}

against

Dictionary<Point, int> Dict2 = new Dictionary<Point, int>();
foreach (KeyValuePair ky in Dict2) {
    //send ky.Value to {ky.Key.X, ky.Key.Y}
}

or

List<Tuple<Point, int>> List1 = new List<Tuple<Point, int>>();
foreach (Tuple<Point, int> t in List1) {
    //send t.Item2 to {t.Item1.X, t.Item1.Y}
}

EDIT: formatting

#23 2016-08-02 21:34:09

Uptight_actor
Anonymous user

Re: [Question] Replacing Blocks?

australian_abyss wrote:

I don't see a reason to have this topic opened. Everyone have written how to make it.
Maybe the owner want to be spoon feeded.

I don't like spoon-feeding. I only ask in the forums when I'm actually lost.

#24 2016-08-02 21:36:33

Terrible_tamale
Anonymous user

Re: [Question] Replacing Blocks?

Uptight_actor wrote:
australian_abyss wrote:

I don't see a reason to have this topic opened. Everyone have written how to make it.
Maybe the owner want to be spoon feeded.

I don't like spoon-feeding. I only ask in the forums when I'm actually lost.

Pretty sure google would be more helpful. Unless it's EE-specific

#25 2016-08-02 22:00:18

Australian_Axe
Anonymous user

Re: [Question] Replacing Blocks?

Terrible_tamale wrote:

Pretty sure google would be more helpful. Unless it's EE-specific

As I mentioned earlier, this would be a bit harder to google as you have to think a little bit abstract, which is generally the hardest part of programming (thinking abstract).

stony_Capitalist wrote:

[Cut away stuff]
My main problem with that it's unnecessary.
[Cut away stuff]

Ever thought why in the init message a single block id is sent and after that all points they occur at? Less resources + the searching would actually go faster. Instead of going through the entire dictionary searching for all the blocks, you can instead give the block id (see how I don't use the word search?) and get all positions related to it.
The reason why a Dict would be smarter than a list with Tuples is again speed (and probably resources and a little bit of code clarity), though all of what I just said can just be wiped away since our current PCs are fast enough and I doubt any bot will really require such kinds of micro optimizations, but it's nice to know either way.

P.S. I actually don't do these things (the dict stuff) myself because I'm too dumb and don't think about it (and other things).

Board footer

Powered by FluxBB

[ Started around 1732417701.5848 - Generated in 0.184 seconds, 12 queries executed - Memory usage: 1.75 MiB (Peak: 1.99 MiB) ]