[SOLVED]Question about Dungeon Generation

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
BulbaMander
Citizen
Posts: 65
Joined: Sat Dec 15, 2012 7:00 pm

[SOLVED]Question about Dungeon Generation

Post by BulbaMander »

I am currently working on a dungeon crawler, the king of the rpg's, and I decided early on I'd have randomly generated maps. However, the time has come for me to implement that, and I just cannot seem to do it right.

I havent tried reverse engineering anything of the sort, but I knew that basicly maps are generated from pieces. So I have four tables which ( in the future will ) have 7 maps in them, and a big table called floors which whill hold the 7 maps put together from the pieces. I figured I coud just setup some conditionals and do a table.insert or just having the coordinates of tiles in the pieces of the map equal their counterparts in the big, finnished map table. Both of these solutions did not work.

In both cases a cannot index error apears, which I presume to mean the item or spot in the table does not exist. After 2 hours of the lua users wiki trying to come up with an easier way to do this without cookie-cutter* code out the wazoo, I decided to come to the embracing arms of the LÖVE community for help. Here is the current map generating function and the map drawing function in the offchance I messed up there too.


TL;DR look at this code and find out why I am getting a cannot index field error.


-- map generation function

Code: Select all

--I use ones alot in here just to see if the actual putting the pieces together part 
          --works. They will be replaced with random numbers and such.

function generateMap()
	for i=1,1 do -- like these ones 
		local Floor = i 
		for i=1,28 do 
			local row = i 
			floors[1][row] = {} 
			for i=1,50 do  
				local col = i
				floors[1][row][col]='' -- i did this in an attempt that maybe since the space inside the tabe didnt exist
				local Table                               --thats why it was having trouble inserting something there 
				local rand = {1,1,1,1}
				if row <= 14 and col <=25 then -- looking to see if the tile we are generating comes from the top left, top right 
					Table = TOP_LEFT                  -- bottom left, or bottom right tables full of pieces. 
				elseif row <=14 and col >=26 then 
					Table = TOP_RIGHT 
				elseif row >=15 and col <=25 then 
					Table = BOTTOM_LEFT 
				elseif row >=15 and col >=26 then 
					Table = BOTTOM_RIGHT 
				end
				table.insert(floors[1][row],col,Table[1][row][col]) -- again the ones here are placeholders 
			end                                -- also ^^ is the line in question that returns the error. 
		end 
	end
end


--the map draw function

Code: Select all


function mapdraw(state)
	if state == 1 then 
		local lvl = game.getLvl()
		for i=1,#floors[lvl] do 
			for ii=1,#floors[lvl][i] do 
				local tiletype = floors[lvl][i][ii] 
				local xextra = 0
				local yextra = 0 
				if tiletype == o then xextra=6;yextra=3 end
				love.graphics.print(tiletype,(ii-1)*12+xextra,(i-1)*12+yextra) 
			end
		end
	end 
end 

[[EDIT]]: I found the problem. I wasnt changeing the local variables to cooperate with the variables for the larger table.
It takes an idiot to do cool things. Thats why they're cool. :emo:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 56 guests