Jump to content




Window api error, but I am not calling the window api at all?

help lua api

2 replies to this topic

#1 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 04 July 2014 - 11:24 PM

Okay so this is my code:
function errorLogging()
cs()
drawBox(1, 51, 1, 1, " ", tc, bc)
printC(">> Error Logging for DHD Program <<", 1, true, tc, bc)
print("> This will display the most recent errors that the")
print("  program has picked up on and logged!")
term.setCursorPos(1,4)
errorDatabase = db.load(errorLog)
for _, v in ipairs(errorDataBase) do
  print(v)
end
drawBox(1, 51, 19, 1, " ", tc, bc)
printC(">> 'B' = Back <<", 19, false, tc, bc)
end

here is the drawBox function:
function drawBox(StartX, lengthX, StartY, lengthY, Text, Color, BkgColor) -- does what is says on the tin.
  local x, y = term.getSize()
  if Color then setCol(Color, BkgColor) end
  if not Text then Text = "*" end
  lengthX = lengthX - 1
  lengthY = lengthY - 1
  EndX = StartX + lengthX 
  EndY = StartY + lengthY
  term.setCursorPos(StartX, StartY)
  term.write(string.rep(Text, lengthX))
  term.setCursorPos(StartX, EndY)
  term.write(string.rep(Text, lengthX))
  for i = StartY, EndY do
    term.setCursorPos(StartX, i)
    term.write(Text)
    term.setCursorPos(EndX, i)   
    term.write(Text)
  end
  resetCol(Color, BkgColor)
  return true 
end

Here is the printC function:
function printC(Text, Line, NextLine, Color, BkgColor) -- print centered
  local x, y = term.getSize()
  x = x/2 - #Text/2
  term.setCursorPos(x, Line)
  if Color then setCol(Color, BkgColor) end
  term.write(Text)
  if NextLine then
    term.setCursorPos(1, NextLine)
  end
  if Color then resetCol(Color, BkgColor) end
  return true 
end

this is only a small part of it, but the error is:
window:248: bad argument: double expected, got boolean

Can't see the problem, and I am not even using the Window API....:/

It gets to the drawing part and sets up the background colour then stops....

#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 04 July 2014 - 11:38 PM

The window api makes troubleshooting some problems unnecessarily difficult, imo - I understand your frustration. In the future, though, please post the entire code, not just snippets/individual functions - this often makes finding the problem easier.

That error, based on the code you posted, means that you are trying to set the cursor position with something *other than* two numbers. 'setCursorPos' expects 2 number values and one (or more) of the variables you are using is probably not being set to any value so it is nil/false.

Try adding some print statements that print the values you are passing to setCursorPos before you actually set the cursor position. Here's an example for your printC function...
print(tostring(x))
print(tostring(Line))
sleep(1)
term.setCursorPos(x, Line)
print(tostring(NextLine))
sleep(1)
term.setCursorPos(1, NextLine)

This will temporarily mess up any screen formatting you have, but it'll let you see what values you are passing and help you track down the troublemaker. Make sure to do this in all your functions.

Hope that helps :)

Edited by Dog, 04 July 2014 - 11:38 PM.


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 05 July 2014 - 01:24 AM

NextLine's the boolean.

Re the window API, as of CC1.6, all advanced systems load multishell on boot. Every tab handled by multishell gets its own window to render to - this is so that if you open more tabs and switch between them, the previous tab content can be restored by redrawing the relevant window when you switch back. Multishell is running even if you don't have more than one tab open (as this is the only way to be prepared for when you do open a second tab).

Thus, any code which renders to the default terminal is going through the window API to do it.

Edited by Bomb Bloke, 05 July 2014 - 01:26 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users