Posted 05 August 2014 - 10:31 PM
Using OpenPeripheral I created a code to detect the number of swords in a chest, print that number, and decide if there are enough. The chest with swords is on the back side, and the monitor is on the right. Here is the code:
m = peripheral.wrap("right")
chest = peripheral.wrap("back")
while true do
items = chest.getAllStacks()
numSwords = 0
for k,v in pairs(items) do
if v.name == "Diamond Sword" then
numSwords = numSwords + 1
end
end
term.clear()
term.setCursorPos(1,1)
if numSwords == 1 then
term.write(numSwords.." sword")
else
term.write(numSwords.." swords")
end
if numSwords < 4 then
m.setCursorPos(1,2)
m.clearLine()
if numSwords == 3 then
m.write("Chest 2 needs 1 sword")
else
m.write("Chest 2 needs "..numSwords-4.." swords")
end
else
m.setCursorPos(1,2)
m.clearLine()
m.write("Chest 2 is stocked")
end
sleep(1)
end
Upon trying to run this code the computer spits out "multiple points". What made the interpreter think I used multiple decimal points in my code?Edited on 05 August 2014 - 08:33 PM