Random Chitchat 2012-2016
Nice changes. I have just two stylistic remarks:
1, You're double-implementing stuff - the Rank command is implemented once for the Console version and once for the In-game version of the command, although they are essentially the same. The usual approach is to extract the common code into a separate function and have both Console and In-game version call that common function. (Imagine a bug was found in your function, you'll have to remember to fix it in two separate places now)
2, Keep those empty lines between functions, they're there for a reason - when quick-flicking through the code, they make it extra-obvious where functions begin and end.

Good job, I hope we'll get more of your changes Smile
Thanks given by:
i'l think of those next time Wink i'm now planning on adding a /toggledownfall command and i also want to change the stop command (since i kinda broke it even more accidentally)
Thanks given by:
Is it possible to add items to a chest using lua?
Thanks given by:
Haven't tested it, but it should be possible. It's not straightforward, though, again, due to multithreading. You need to use cWorld:DoWithChestAt(BlockX, BlockY, BlockZ, CallbackFunction) and do the chest manipulation in the CallbackFunction.
Thanks given by:
so something like World:DoWitchChest(BlockX, BlockY, BlockZ, cInventory:GetInventory():AddItem( Item ) )
Thanks given by:
No, it's the same as ForEachPlayer()-style functions - you need to write a function to call.
Code:
local Item1 = ...;
local Item2 = ...;

local  Add2Items = function (Chest)
  -- Chest is of type cChestEntity, currently very under-API-ed
  Chest:SetSlot(1, Item1);
  Chest:SetSlot(2, Item2);
end

World:DoWithChestAt(BlockX, BlockY, BlockZ, Add2Items);
Thanks given by:
it works thanks Smile
Thanks given by:
Code:
local  Add2Items = function (Chest)
  -- Chest is of type cChestEntity, currently very under-API-ed
  Chest:SetSlot(1, Item1);
  Chest:SetSlot(2, Item2);
end

Just to clear up something, could that code be rewritten as:

Code:
local function Add2Items(Chest)
  --...
  Chest:SetSlot(1, Item1);
  Chest:SetSlot(2, Item2);
end

If they aren't, what's the difference?
Thanks given by:
Bearbin, I have no idea, I just use the first approach because that's what worked for me when I tried. I suppose the second will work as well.
Thanks given by:
(03-26-2013, 06:44 AM)bearbin Wrote:
Code:
local  Add2Items = function (Chest)
  -- Chest is of type cChestEntity, currently very under-API-ed
  Chest:SetSlot(1, Item1);
  Chest:SetSlot(2, Item2);
end

Just to clear up something, could that code be rewritten as:

Code:
local function Add2Items(Chest)
  --...
  Chest:SetSlot(1, Item1);
  Chest:SetSlot(2, Item2);
end

If they aren't, what's the difference?

I don't think there's a difference
Thanks given by:




Users browsing this thread: 201 Guest(s)