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-05-04 12:51:58, last edited by kurtv13 (2015-05-06 10:27:58)

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

[SOLVED] How to get the number of "empty" blocks

How do I check the number of empty blocks (Block ID 0) in my world at a certain interval without having to call /loadlevel everytime? //forums.everybodyedits.com/img/smilies/smile


Pfffffttt

Offline

#2 2015-05-04 12:55:37

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

Re: [SOLVED] How to get the number of "empty" blocks

Do you have a world-deserializer?

You can use that.


shh i have returned

Offline

#3 2015-05-04 12:56:52

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

Re: [SOLVED] How to get the number of "empty" blocks

Start off by deserializing your worlddata in the Init message (obviously).
Then for every "b" event, check if it deleted an 'empty' block or placed one.
Keep track of the amount of 'empty' blocks through an int you constantly add or substract one from.
You can use a Timer to read the variable every now and then.

Offline

#4 2015-05-04 12:57:06

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] How to get the number of "empty" blocks

isn't world data only received when you join the world and when the world is reset via /loadlevel?


Pfffffttt

Offline

#5 2015-05-04 12:59:53

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] How to get the number of "empty" blocks

den3107 wrote:

Start off by deserializing your worlddata in the Init message (obviously).
Then for every "b" event, check if it deleted an 'empty' block or placed one.
Keep track of the amount of 'empty' blocks through an int you constantly add or substract one from.
You can use a Timer to read the variable every now and then.

oh right. I guess I could try that


Pfffffttt

Offline

#6 2015-05-04 13:03:18

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

Re: [SOLVED] How to get the number of "empty" blocks

loadlevel has it's own event
case "reset":


shh i have returned

Offline

#7 2015-05-04 13:11:04

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] How to get the number of "empty" blocks

madiik wrote:

loadlevel has it's own event
case "reset":

Yeah, but the problem is that I don't want to /loadlevel every time I wanna check the empty block count. hm


Pfffffttt

Offline

#8 2015-05-04 13:40:03

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] How to get the number of "empty" blocks

kurtv13 wrote:
den3107 wrote:

Start off by deserializing your worlddata in the Init message (obviously).
Then for every "b" event, check if it deleted an 'empty' block or placed one.
Keep track of the amount of 'empty' blocks through an int you constantly add or substract one from.
You can use a Timer to read the variable every now and then.

oh right. I guess I could try that

*FOLLOW UP QUESTION* How do I check if a player just simply replaced a block? Because in this case, I wouldn't want to subtract to the empty block count.


Pfffffttt

Offline

#9 2015-05-04 13:50:37

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

Re: [SOLVED] How to get the number of "empty" blocks

kurtv13 wrote:
madiik wrote:

loadlevel has it's own event
case "reset":

Yeah, but the problem is that I don't want to /loadlevel every time I wanna check the empty block count. hm

Then you should need to keep track of them an empty block is deleted or placed.
Harder to code but a bit more friendly and faster too.

Offline

#10 2015-05-04 23:20:47, last edited by DarkDragon4900 (2015-05-04 23:22:10)

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

Re: [SOLVED] How to get the number of "empty" blocks

You don't need to loadlevel every time.
Modify the roomdata whenever a block is placed.
Owner blocks have their own message types, too, so you might wanna check whenever they're placed on their cases.
Unless you don't need them.

kurtv13 wrote:
kurtv13 wrote:
Hidden text

*FOLLOW UP QUESTION* How do I check if a player just simply replaced a block? Because in this case, I wouldn't want to subtract to the empty block count.

case "b":
    int layer = e.GetInt(0), x = e.GetInt(1), y = e.GetInt(2), bid = e.GetInt(3); // Set the variables you get from the message.
    if (bid != 0 && roomData[layer, x, y].BlockID == 0) // Check if the block that was previously there was an empty one, and if the new one isn't 0.
        emptyBlocks--; // Decrease the amount of empty blocks by one.
    roomData[layer, x, y].BlockID = bid; // Set the new block at the given coords to the given block id to keep your room data updated.
    break;

Offline

Wooted by:

#11 2015-05-05 03:01:35

kurtv13
Member
From: Everywhere
Joined: 2015-04-24
Posts: 59

Re: [SOLVED] How to get the number of "empty" blocks

DarkDragon4900 wrote:

You don't need to loadlevel every time.
Modify the roomdata whenever a block is placed.
Owner blocks have their own message types, too, so you might wanna check whenever they're placed on their cases.
Unless you don't need them.

kurtv13 wrote:
kurtv13 wrote:
Hidden text

*FOLLOW UP QUESTION* How do I check if a player just simply replaced a block? Because in this case, I wouldn't want to subtract to the empty block count.

case "b":
    int layer = e.GetInt(0), x = e.GetInt(1), y = e.GetInt(2), bid = e.GetInt(3); // Set the variables you get from the message.
    if (bid != 0 && roomData[layer, x, y].BlockID == 0) // Check if the block that was previously there was an empty one, and if the new one isn't 0.
        emptyBlocks--; // Decrease the amount of empty blocks by one.
    roomData[layer, x, y].BlockID = bid; // Set the new block at the given coords to the given block id to keep your room data updated.
    break;

This should do the trick. Many thanks!


Pfffffttt

Offline

kurtv131430791295501489

Board footer

Powered by FluxBB

[ Started around 1732216074.8338 - Generated in 0.247 seconds, 10 queries executed - Memory usage: 1.53 MiB (Peak: 1.7 MiB) ]