Jump to content




Multiple points error using code with OpenPeripheral


  • You cannot reply to this topic
3 replies to this topic

#1 onContentStop

  • Members
  • 6 posts

Posted 05 August 2014 - 09: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 by onContentStop, 05 August 2014 - 09:33 PM.


#2 onContentStop

  • Members
  • 6 posts

Posted 05 August 2014 - 09: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 by onContentStop, 05 August 2014 - 09:40 PM.


#3 flaghacker

  • Members
  • 655 posts

Posted 05 August 2014 - 11:00 PM

I think putting a space inbetween the 4 and the ".." should fix the problem.

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 05 August 2014 - 11:31 PM

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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users