Log In  


I am making a puzzle game on a 6x6 grid at the moment. Every cell has two values: 1) The colour/type of cell 2) the variable of that cell
Thus every cell is two hexadecimal digits. I've made a level editer and all but I've run into a problem with level loading. Shortened to the problematic code, here is the problem:

levels={
	"0000000000000000000000000000000000000000000000000011c0c07000000000000000",
	"0000000000000000000000000000000000000000000000000011c0c07000000000000000"
}
function loadlevel(n)
	local ltol=levels[n]
	powerlevel=0
	for i=1,#ltol/2do
		local s1=1+(i-1)*2
		local s2=s1+1
		level[i]=sub(ltol,s1,s2)
	end
end
function _init()
	nl=2
	go=false
	loadlevel(1)
	go=true
end
function _update()
	local nogo=false
	for i=1, 16do
		if level[i]!="00"then
			nogo=true
		end
	end
	if go and not nogo then
		loadlevel(nl)
		nl+=1
	end
end

Error code:

runtime error line 8 tab 0
	for i=1,#ltol/2do
attempt to get length of local 'ltol' (a nil value)
at line 0 (tab 0)

I really can't seem to figure out a solution to this.
Cheers in advance!



debug you go/nogo logic - nl is incremented 30 times per second, you are trying to load level 3 which is obviously nil.


Ah. Just realised the problem. Initially in the design process for the game, it was played on a 4x4 grid, which in the end didn't allow for good gameplay, so I upped it to 6x6. I guess half of my brain still thinks that there are 36 items and not 16. What a k e r f u f f l e .



[Please log in to post a comment]