Jump to content




Need help, strange error..

help lua

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

#1 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 20 December 2012 - 10:43 AM

So here I was coding some, and I stumbled upon a strange error message:

API:259: index expected, got nil


Now heres the code that I am running:
Spoiler

I am running this via a test file:
Spoiler


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 December 2012 - 11:17 AM

Post the full code and the full error message.

#3 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 20 December 2012 - 11:21 AM

View PostLyqyd, on 20 December 2012 - 11:17 AM, said:

Post the full code and the full error message.

That is the full error message!
The rest of the message is just the file name : line number, wich I have marked out.
Anyways, I added it

Entire code: sure, added. It's from the making of a OS btw

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 20 December 2012 - 11:29 AM

Do some debug lines like, print(window.width[windowID]) and print(type(window.width[windowID]))
do it for the others to and check what they are.

#5 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 20 December 2012 - 11:31 AM

View PostremiX, on 20 December 2012 - 11:29 AM, said:

Do some debug lines like, print(window.width[windowID]) and print(type(window.width[windowID]))
do it for the others to and check what they are.
I've already, but it dosen't help, still the same error and no debug messages

EDIT: I think I might have read your question wrong... This is the output from the respective code:
print("Window "..windowID)
print("Width: "..window.width[windowID])
print("Height: "..window.height[windowID])

for width = 0, window.width[windowID] do
	for height = 0, window.height[windowID] do
		occu[width][height] = windowID
	end
end
Output:
Window 1
Width: 25.5
Height: 9.5
API:263: index expected, got nil

I think I know whats happening here..

EDIT 2: Nope I was wrong, still same error!

#6 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 20 December 2012 - 11:48 AM

I think I found the problem:
When it tries to set occu[0] it cant, because in lua tables start in 1...

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 20 December 2012 - 11:50 AM

actually, you can have a 0 index.
Indices can be anything you want, even negative numbers.

#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 20 December 2012 - 12:08 PM

Yeah I was going to say that jag, but I first tested it and you can. But it just prints blank but doesn't error.

#9 ChunLing

  • Members
  • 2,027 posts

Posted 20 December 2012 - 06:45 PM

	   for width = 0, window.width[windowID] do
-- occu[width] = {} -- uncomment this if occu[width] was not already a table
			    for height = 0, window.height[windowID] do
print(type(width),width,type(height),height)
					    occu[width][height] = windowID !!!!!!!!{{{ 'THIS LINE' }}}!!!!!!!!
			    end
	    end
The error indicates that either width or height was a nil at some point, so print those out for every value. Also, if you didn't make occu[width] a table before, you need to do so before attempting to populate it (that should have given a different error message, though).

#10 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 20 December 2012 - 08:37 PM

I fixed it just by doing this:
if not occu[width+window.position_x[windowID]] then
	occu[width+window.position_x[windowID]] = {}
end






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users