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

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

Started by Konlab, 23 May 2014 - 10:11 AM
Konlab #1
Posted 23 May 2014 - 12:11 PM
Hi!
I'm developing a game, called GoDeeper!
But I have a problem: if I begin the game and I press a key then: "window:247:bad argument: double expected, got nil"

please fix!
pastebin link: http://pastebin.com/LghsK2Yv

Also in lua are doubles?
I know, in C are doubles, and the lua is written in C. But please fix!
KingofGamesYami #2
Posted 23 May 2014 - 01:38 PM


term.setCursorPos(xto,yto) --this line is passed nil, 1

function go() --# cur & next have not been defined, thus prev is set to nil
  prev = cur
  cur = next
  next = math.random(2,25)
  level(prev,1) --#this line passes nil, 1
  level(cur,2)
  level(next,3)
end
Konlab #3
Posted 23 May 2014 - 01:43 PM
And at the line 5 and at the line 6 cur and next are defined



term.setCursorPos(xto,yto) --this line is passed nil, 1

function go() --# cur & next have not been defined, thus prev is set to nil
  prev = cur
  cur = next
  next = math.random(2,25)
  level(prev,1) --#this line passes nil, 1
  level(cur,2)
  level(next,3)
end
Lignum #4
Posted 23 May 2014 - 05:19 PM
Also in lua are doubles?
I know, in C are doubles, and the lua is written in C.
ComputerCraft uses LuaJ which is written in Java, not in C.
But yes, there are doubles in Lua and LuaJ, in fact everything is a double, which I personally am not too keen on.


local someDouble = 5.2 --# Works!
local someInt = 5 --# Works, too.

print(type(someInt)) --# Prints "number".
print(type(someDouble)) --# Prints "number".

From that we can conclude that there aren't really number types in Lua and thusly everything counts as a "number" type.
Konlab #5
Posted 23 May 2014 - 05:29 PM
I know what is double and what is int, because I learn C, too.



term.setCursorPos(xto,yto) --this line is passed nil, 1

function go() --# cur & next have not been defined, thus prev is set to nil
  prev = cur
  cur = next
  next = math.random(2,25)
  level(prev,1) --#this line passes nil, 1
  level(cur,2)
  level(next,3)
end

Please send me the fixed code.
Lyqyd #6
Posted 23 May 2014 - 05:35 PM
That's not how Ask a Pro works, generally. He's pointed out the issue causing the error, so you should at least try to go fix the problem yourself rather than just demanding fixed code. We aren't here to write your program for you, merely to help you learn how to fix it yourself. Sometimes people do decide to provide code as well, but that is at their discretion, and is usually only because the question asker has put a lot of effort into the question.
Konlab #7
Posted 23 May 2014 - 05:37 PM
I am trying to fix the code 10 hours ago I'm working only on it, but still gives an error
Lyqyd #8
Posted 23 May 2014 - 05:39 PM
Then post the current code and the full text of the error you get while running it.
Konlab #9
Posted 23 May 2014 - 05:42 PM
I run the code and I get: Crashed:<and the title of the post>
The Crashed is because I used pcall()
Lyqyd #10
Posted 23 May 2014 - 05:44 PM
So, you haven't changed anything in the code since you posted it on the pastebin link in the first post? You should make the changes suggested by KingOfGamesYami and try running it again.
Konlab #11
Posted 23 May 2014 - 06:26 PM
But the KingOfGamesYani's version and between the first version isn't any difference!
Lignum #12
Posted 23 May 2014 - 06:40 PM
But the KingOfGamesYani's version and between the first version isn't any difference!
It has comments which should point you in the right direction.
Lyqyd #13
Posted 23 May 2014 - 06:51 PM
But the KingOfGamesYani's version and between the first version isn't any difference!

He is suggesting where you need to make changes in the code. You have to go back and actually fix it rather than just expecting the fix to be handed to you on a silver platter. We are trying to show you where the problem is and help you learn why it occurred and how to fix it, which will be more helpful to you in the long run. You have to invest some effort into this process as well, instead of just posting a problem and sitting around demanding that someone post a completely fixed piece of code.