This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
onContentStop's profile picture

Multiple points error using code with OpenPeripheral

Started by onContentStop, 05 August 2014 - 08:31 PM
onContentStop #1
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
onContentStop #2
Posted 05 August 2014 - 10:36 PM
Upon reviewing my code I found a line that may have caused the error.

m.write("Chest 2 needs "..numSwords-4.." swords")
The coloring of the dot after the 4 implies that it read the 4 as a decimal but encountered another one immediately after it.
EDIT: Making another variable instead of concatenating math with a string fixed it. Leaving this thread up for future reference.
Edited on 05 August 2014 - 08:40 PM
flaghacker #3
Posted 06 August 2014 - 12:00 AM
I think putting a space inbetween the 4 and the ".." should fix the problem.
theoriginalbit #4
Posted 06 August 2014 - 12:31 AM
Alternatively also surrounding the math in brackets would solve it too.
This is most definitely Lua thinking that you've done a number with multiple decimal places.