Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
i'l think of those next time 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)
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Is it possible to add items to a chest using lua?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
so something like World:DoWitchChest(BlockX, BlockY, BlockZ, cInventory:GetInventory():AddItem( Item ) )
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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);
Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
it works thanks
Posts: 1,469
Threads: 57
Joined: Jul 2012
Thanks: 66
Given 127 thank(s) in 108 post(s)
03-26-2013, 06:44 AM
(This post was last modified: 03-26-2013, 06:45 AM by bearbin.)
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?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
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.
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
(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
|