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

window:247:bad argument: double expected, got nil

Started by Beatsleigher, 20 May 2014 - 08:02 PM
Beatsleigher #1
Posted 20 May 2014 - 10:02 PM
Hey guys, I'm currently playing on a server which isn't mine (found out about it here in the forums) and I'm trying to create a boot loader and turtle server, but I can't even test the most basic things:

I have nothing in my code that uses the window-API, but I'm still getting the error above in the title.


-- [[ Copyright (c) Beatsleigher 2014 ]] --
-- [[ Disable Termination ]] --
os.pullEvent = os.pullEventRaw
-- [[ Variables ]] --
VERSION = "1.0"
VER = VERSION
TITLE = "TURTLESERV SErVER BOOT-UP MANAGER"
xLen, yLen = term.getSize()
-- [[ Printing Methods ]] --
local function clear()
  term.clear()
  term.setCursorPos(1,1)
end
local function printCentre(height, data)
  xPos = xLen / 2 - string.len(data) / 2
  term.setCursorPos(xPos, height)
  print(data)
end
local function printRight(height, data)
  xPos = xLen - string.len(data)
  term.setCursorPos(xPos, height)
  print(data)
end
local function printHeader()
  clear()
  print(TITLE)
  printRight(1, VER)
end
-- [[ Main Method ]] --
local function main()
  printHeader()
end
-- [[ Program Entry Point ]] --
main()

That's all the code that I have at the moment, but I'm getting that weird error. I've been using this code for at least two years, now - It's never failed me.
Is this just my being dumb or is this a bug in CC?
How can I fix this?

Thanks in advance.
KingofGamesYami #2
Posted 20 May 2014 - 10:25 PM
I would use math.floor( xLen / 2 - ( data:len() ) ) instead of what you have, to avoid accidentally passing decimals.
Yevano #3
Posted 20 May 2014 - 10:48 PM
From window.lua, starting at line 246:



function window.setCursorPos( x, y )
    nCursorX = math.floor( x ) -- This is where your error occurs.
    nCursorY = math.floor( y )
    if bVisible then
        updateCursorPos()
    end
end

Since CC1.6, the window API is used for the multishell I think. So, when you call term.setCursorPos, the call is deferred to the window function. On line 247, math.floor gets called with argument x, so I'd think it must be that you're passing nil there somehow. Looking at your code though, that doesn't seem to be the case. Have you changed it at all? And, are you running CC1.63?
BlockSmith #4
Posted 21 May 2014 - 08:30 AM
You aren't getting a value for the xLen variable in the function because it isn't being passed to it.

[[ Copyright (c) Beatsleigher 2014 ]]
[[ Disable Termination ]]
os.pullEvent = os.pullEventRaw
[[ Variables ]]
VERSION = "1.0"
VER = VERSION
TITLE
= "TURTLESERV SErVER BOOT-UP MANAGER"
xLen, yLen = term.getSize()
[[ Printing Methods ]]
local function clear()
term.clear()
term.setCursorPos(1,1)
end
local function printCentre(height, data, x) –Added arguement x here
xPos = x / 2 - string.len(data) / 2 –Changed xLen to x
term.setCursorPos(xPos, height)
print(data)
end
local function printRight(height, data, x) –Added arguement x here
xPos = x - string.len(data) –Changed xLen to x
term.setCursorPos(xPos, height)
print(data)
end
local function printHeader()
clear()
print(TITLE)
printRight(1, VER, xLen) –Passing xLen as the arguement for x
end
[[ Main Method ]]
local function main()
printHeader()
end
[[ Program Entry Point ]]
main()


It may not be the very best code, but this worked fine for me.
Yevano #5
Posted 21 May 2014 - 09:30 PM
BlockSmith, why would that be any different? xLen is a global, so it shouldn't be nil.

I just tested OP's original code in CC 1.63 and I don't get any errors.
BlockSmith #6
Posted 21 May 2014 - 10:56 PM
I didn't see any issues with his code either. So I just revised it the way I posted here and it worked. Sometimes functions or variables get squirrely and need a pointer holding their hands along the way. It is doing the same as his original code, just in a different way. If the original posted code works then we've missed something else entirely.
Beatsleigher #7
Posted 22 May 2014 - 12:08 AM
From window.lua, starting at line 246:



function window.setCursorPos( x, y )
	nCursorX = math.floor( x ) -- This is where your error occurs.
	nCursorY = math.floor( y )
	if bVisible then
		updateCursorPos()
	end
end

Since CC1.6, the window API is used for the multishell I think. So, when you call term.setCursorPos, the call is deferred to the window function. On line 247, math.floor gets called with argument x, so I'd think it must be that you're passing nil there somehow. Looking at your code though, that doesn't seem to be the case. Have you changed it at all? And, are you running CC1.63?

Yup, CC 1.63 on Minecraft 1.6.4.
I have no idea what caused this. Using the same code in a different program worked flawlessly.
Yevano #8
Posted 22 May 2014 - 12:54 AM
Yup, CC 1.63 on Minecraft 1.6.4.
I have no idea what caused this. Using the same code in a different program worked flawlessly.

Is this part of a much larger program? If so, then it could be some other part of the code causing it. Could you post the rest of your code?