Random Chitchat 2012-2016
so i have this:
	local X = math.floor(Player:GetPosX())
	local Y = math.floor(Player:GetPosY())
	local Z = math.floor(Player:GetPosZ())
        local Radius = Split[3]
	for X = -Radius, Radius do
		for Y = -Radius, Radius do
			for Z = -Radius, Radius do
				Execute( X, Y, Z, Player, Split, Target, World )
			end
		end
	end
but it keeps saying that X, Y, Z are 0 and then they do the radius stuff around X=0, Y=0 and Z = 0
Thanks given by:
The point is, with a for loop, the computer knows the number of iterations, so it can optimize it in some ways.

Anyway, for a more complete example: (I hope I'll get it right, no promises though)
Code:
local PlayerX = a_Player:GetPosX();
local PlayerY = a_Player:GetPosY();
local PlayerZ = a_Player:GetPosZ();
local Area = cBlockArea();
if (not(Area:Read(a_Player:GetWorld(), PlayerX - 8, PlayerX + 8, PlayerY - 8, PlayerY + 8, PlayerZ - 8, PlayerZ + 8, cBlockArea.baTypes + cBlockArea.baMetas))) then
  -- Cannot read the area around player, bail out
  return;
end

local x, y, z;
for y = -8, 8 do
  for z = -8, 8 do
    for x = -8, 8 do
      local BlockType, BlockMeta;
      BlockType, BlockMeta = Area:GetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta);  
        -- stupid ToLua makes us write the last two arguments, they are otherwise useless and unused
      -- Do something with the block
    end  -- for x
  end  -- for z
end  -- for y

I don't know what your Execute function does, I suppose it's doing something with block in the world using World:GetBlock(); that is gonna be really slow. You really really want to use the BlockArea version of this.
Thanks given by: NiLSPACE
thanks i can now rollback peopleBig Grin the only problem is that it is realy realy slow. becouse for each block it does this:
	if Block:FindKey("X: " .. X .. "Y: " .. Y .. "Z: " .. Z .. " World: " .. Player:GetWorld():GetName()) ~= -1 then
		local Target = Block:GetValue("X: " .. X .. "Y: " .. Y .. "Z: " .. Z .. " World: " .. Player:GetWorld():GetName() , "Player")
		if Target == Split[2] then
			if Block:GetValue("X: " .. X .. "Y: " .. Y .. "Z: " .. Z .. " World: " .. Player:GetWorld():GetName() , "PlacedOrBroken") == "Placed" then
				World:SetBlock(X, Y, Z, 0, 0)
			else
				BlockType = Block:GetValue("X: " .. X .. "Y: " .. Y .. "Z: " .. Z .. " World: " .. Player:GetWorld():GetName() , "BlockType")
				BlockID = tonumber(BlockType)
				BlockMeta = Block:GetValue("X: " .. X .. "Y: " .. Y .. "Z: " .. Z .. " World: " .. Player:GetWorld():GetName() , "BlockMeta")
				World:SetBlock(X, Y, Z, BlockID, BlockMeta)
			end
			Block:DeleteKey("X: " .. X .. "Y: " .. Y .. "Z: " .. Z .. " World: " .. Player:GetWorld():GetName())
		end
	end
any ideas how i could make it work faster?
Thanks given by:
1, Cache values. You're building the key name, then forgetting it, then rebuilding it again, then forgetting, then rebuilding... Use a local variable to build it once and then use it.
2, What class exactly is Block? I'm guessing that its FindKey() and GetValue() do almost the same - both search an underlying storage for a key name and return its position or value. Can't you use just one?

On a different note, I've found that the bug in Floody has been there before, so it's not been introduced by my optimization. So I committed the faster code, now I have to track down the bug.
Thanks given by:
FindKey checks if a key exists and GetValue gives the value of a key i believe. Block is cIniFile(PLUGIN:GetLocalDirectory() .."/Blocks.ini")
Thanks given by:
So what does GetValue do if the key doesn't exist? Can't you use that to your advantage?

(and you should really post that to your Learning threadTongue )
Thanks given by:
I fixed the server stopping on Linux, turns out it was something completely different than I originally thought.

cListenThread was counting on OS waking up from a select() call when one of the sockets was closed. Apparently, this isn't the case on Linux, so I put in additional wakeups by timeout every 1 second (semi-busywait).
Thanks given by:
omg TortoiseSVN is frustrating. i want to commit my changes to the core but it wants to commit it to http://mc-server.googlecode.com/svn/trunk/ without my allowing to change it >.<


Attached Files Thumbnail(s)
   
Thanks given by:
You need to use the Switch command to switch the repository to the proper https path, then you can commit.
Thanks given by:
thanks. did my first commit now Wink
Thanks given by:




Users browsing this thread: 5 Guest(s)