758 posts
Location
Budapest, Hungary
Posted 22 January 2013 - 08:11 AM
I don't know if this is a bug or not, but at least it's interesting. When I try to set the command for a Command Block, it executes the previous command stored in it. I think I have done something wrong, so I have only one question:
How to use a Command Block?
I tried to solve my problem using the Interactive Lua Prompt:
local tCommandBlock = peripheral.wrap("left")
tCommandBlock.setCommand("toggledownfall") -- nothing happened
tCommandBlock.runCommand() -- it began raining, what a surprise
tCommandBlock.setCommand("give lbphacker 137 1") -- it stopped raining, WTF?!
-- oh what? "@: Toggled downfall" ?!
So this is my problem - Please help me…
LBPHacker
2088 posts
Location
South Africa
Posted 22 January 2013 - 08:17 AM
Maybe the use of 'give lbphacker 137 1' is wrong and it's using the previously correct command which is rainfall. I've never used this peripheral before though.
maybe the name is CasE-sEnsItiVe
2005 posts
Posted 22 January 2013 - 08:28 AM
Did you try to run the command after you set it?
I can see a command block that has had the command to toggle rainfall removed then ceasing to impose the environment change…that actually makes a good bit of sense.
758 posts
Location
Budapest, Hungary
Posted 22 January 2013 - 08:44 AM
Maybe the use of 'give lbphacker 137 1' is wrong and it's using the previously correct command which is rainfall. I've never used this peripheral before though.
maybe the name is CasE-sEnsItiVe
Nope - When I set the command 'give lbphacker 137 1' first, it gives me a command block, nothing's wrong whit the command.
Did you try to run the command after you set it?
I can see a command block that has had the command to toggle rainfall removed then ceasing to impose the environment change…that actually makes a good bit of sense.
Umm… So… Sorry but… What?
When I type
tCommandBlock.setCommand("give lbphacker 137 1")
tCommandBlock.runCommand()
it works, but then I try to change the command and I get another command block.
2088 posts
Location
South Africa
Posted 22 January 2013 - 08:51 AM
Try
cmd.runCommand("give lbphacker 137 1")
2005 posts
Posted 22 January 2013 - 08:52 AM
Okay, try something like this:
local tCommandBlock = peripheral.wrap("left")
tCommandBlock.setCommand("toggledownfall")
tCommandBlock.runCommand()
sleep(5) --just so you can see it raining
tCommandBlock.setCommand("give lbphacker 137 1")
tCommandBlock.runCommand() --what happens at this point?
The point I was making earlier is that I would expect toggledownfall to be "imposed" on the environment only for as long as there was a command block with that command currently. Change the command, and the command block shouldn't be "imposing" the change on the environment anymore, regardless of whether it was toggled on or off when the command was changed. This doesn't seem like a bug to me…imagine how it would be if, once you had toggled rain on, you could never go back to a normal cycling weather pattern, but always had to explicitly toggle the rain. Okay, that doesn't sound all that bad in minecraft, I'm not really that fond of the rain and wouldn't mind if it were toggled off permanently. But I think that what you were seeing is the removal of the toggledownfall command acting just as it should, the command block ceasing to impose a change on the environment.
758 posts
Location
Budapest, Hungary
Posted 22 January 2013 - 09:03 AM
Try
cmd.runCommand("give lbphacker 137 1")
Nope - Executes the last command set by .setCommand - I don't think .runCommand accepts parameters…
Okay, try something like this:
local tCommandBlock = peripheral.wrap("left")
tCommandBlock.setCommand("toggledownfall")
tCommandBlock.runCommand()
sleep(5) --just so you can see it raining
tCommandBlock.setCommand("give lbphacker 137 1")
tCommandBlock.runCommand() --what happens at this point?
"[@: Given Command Block (ID: 137) * 1 to LBPHacker]"
"[@: Given Command Block (ID: 137) * 1 to LBPHacker]"
"[@: Toggled downfall]"
"[@: Toggled downfall]"
I mean
2088 posts
Location
South Africa
Posted 22 January 2013 - 09:10 AM
<p>
Try
cmd.runCommand("give lbphacker 137 1")
Nope - Executes the last command set by .setCommand - I don't think .runCommand accepts parameters…
Try only using runCommand("command string") without using setCommand. Because according to
this page, runCommand does accept parameters
758 posts
Location
Budapest, Hungary
Posted 22 January 2013 - 09:13 AM
I've seen this page before, and (I think) it's not the official command block peripheral. It says it's for CC 1.46.
2005 posts
Posted 22 January 2013 - 01:38 PM
Just to be clear here, you're getting block 137, right? Are you getting it twice? And then the rain is toggling…twice?
758 posts
Location
Budapest, Hungary
Posted 22 January 2013 - 09:55 PM
Exactly
7508 posts
Location
Australia
Posted 22 January 2013 - 10:05 PM
I noticed this too, I just thought it was me doing something wrong… I tried a few things and couldn't figure out why. I did find if I was changing more than one using redstone output was better than runCommand because only every second one triggered twice… And I also decided to use /weather clear 6000 so i would never have rain :P/>
53 posts
Location
Adelaide, Australia.
Posted 22 January 2013 - 10:21 PM
Command blocks work with a '/' and without a '/'. Therefore you can have a command like /give notch 137 1 and give notch 137 1. Command blocks arent case-seneitive. Can someone make link the CommandBlock API?
515 posts
Location
Australia
Posted 22 January 2013 - 11:12 PM
Yeah I noticed the bug too :P/> I managed to figure it out. Try this:
local tCommandBlock = peripheral.wrap("left")
tCommandBlock.setCommand("")
tCommandBlock.setCommand("/toggledownfall")
tCommandBlock.setCommand("")
tCommandBlock.setCommand("/give lbphacker 137 1")
You might need to run it twice in order to run it properly, so it "cleans up" the command block. After that it'll work like a charm every time (hopefully). It's just that the command block's command input needs to be "blank" to start with
758 posts
Location
Budapest, Hungary
Posted 23 January 2013 - 12:12 AM
CommandBlock API
You can list the methods of every peripherals with this
local tPeripheral = peripheral.wrap("left")
local pwrap = fs.open("pwrap.txt", "w")
for k, v in pairs(tPeripheral) do pwrap.writeLine(tostring(k)) end
pwrap.close()
local tCommandBlock = peripheral.wrap("left")
tCommandBlock.setCommand("")
tCommandBlock.setCommand("/toggledownfall")
tCommandBlock.setCommand("")
tCommandBlock.setCommand("/give lbphacker 137 1")
I'd prefer
local tCommandBlock = peripheral.wrap("left")
tCommandBlock.setCommand("/toggledownfall")
tCommandBlock.setCommand("")
tCommandBlock.setCommand("/give lbphacker 137 1")
tCommandBlock.setCommand("")
It works… But…
But look at that code! .setCommand's everywhere. And it toggles the rain and throws a Command Block in my face. Something's not right.
2447 posts
Posted 23 January 2013 - 01:53 AM
Agreed. Must be a bug in my code. Will look into it.
2447 posts
Posted 23 January 2013 - 03:16 AM
Ok, fixed. I had the task iteration order backwards. For now, you can work round by putting your commands in backwards - e.g. if you want toggledownfall, followed by give, you'd do this:
cmd = peripheral.wrap("left")
cmd.runCommand() -- yes, makes no sense
cmd.setCommand("give @p 1")
cmd.runCommand()
cmd.setCommand("toggledownfall")
The other alternative is sleeping 0.05 in between commands - which will mean that the command will get executed on the next tick, in the right order.
758 posts
Location
Budapest, Hungary
Posted 23 January 2013 - 03:55 AM
Oh - It makes sense now :P/> An operation list iterated backwards…
I hope that'll be fixed in the next version.
I'm blind…
Edited on 23 January 2013 - 04:57 AM
2447 posts
Posted 23 January 2013 - 05:19 AM
I hope that'll be fixed in the next version
Ok, fixed.
46 posts
Location
NWIndiana
Posted 23 January 2013 - 06:17 PM
of course I noticed this AFTER I made another thread. HOW did this not come up in my searches?
Anyway, thanks for the fix. I'll get the Owner to update.