2 posts
Posted 08 January 2014 - 03:45 PM
Hello,
Im trying to pass a variable to commandBlock.setCommand() like this
write("please enter the amount")
local var1 = read ("*")
local var2 = ("econ sub @p ")
local var3 = (var2..var1)
commandBlock.peripheral.wrap ("left")
commandBlock.setCommand(var3)
commandBlock.runCommand()
it returns a "attempt to index ? (a nil value)"
what am i doing wrong ?
thanks for u reply in advance.
8543 posts
Posted 08 January 2014 - 04:57 PM
Have you enabled the command block peripheral interface in the config? Do you have OpenPeripheral installed?
Also, to wrap the peripheral, it's:
local commandBlock = peripheral.wrap("left")
2 posts
Posted 11 January 2014 - 05:00 AM
Yes, i have it enabled , i can pass prewrited commands to the block but can't pass string variables to it, it just return me "attempt to index ? (a nil value)
oh and no i dont have OpenPeripheral, as the provided link doesn't work anymore.
I have OpenPeripheral installed now, but i still can't pass variables to commandBlock.setCommand()
for example if i write this :
commandBlock.peripheral.wrap ("left")
commandBlock.setCommand("econ bank create @p")
commandBlock.runCommand()
it works perfectly, the command is passed and lauched to the commandBlock.
now if try this :
write("please enter the amount")
local var1 = read ("*")
local var2 = ("econ sub @p ")
local var3 = (var2..var1)
commandBlock.peripheral.wrap ("left")
commandBlock.setCommand(var3)
commandBlock.runCommand()
and when i run the program it stop on commandBlock.setCommand(var3) line, with this error "attempt to index ? (a nil value)"
sorry im new with lua and maybe im not doing the correct method to deal with commandblocks, so any help would be apreciated.
8543 posts
Posted 12 January 2014 - 11:06 AM
I asked about OpenPeripheral because if you have it installed, it won't work at all.
Also, did you even read what I wrote earlier? You can't wrap a peripheral that way. Either that isn't the code you're using or you're copying your code into the forums wrong. Either way, I can't help you fix this until I see the code that you're actually using.