How to choose renadom map from a list?

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
pxlzvr
Prole
Posts: 2
Joined: Tue Apr 08, 2014 7:33 pm

How to choose renadom map from a list?

Post by pxlzvr » Wed Apr 09, 2014 6:20 am

So for example I have 10 different maps in a map.lua file. They look like this:

1111
1001
1001
1111

0 - floor tile
1 - wall

i need to choose 1 random room from a list at the start of the game.

User avatar
nuno
Party member
Posts: 137
Joined: Wed Dec 11, 2013 12:00 pm
Location: Portugal
Contact:

Re: How to choose renadom map from a list?

Post by nuno » Wed Apr 09, 2014 8:43 am

if you have an array of tables, like

Code: Select all

rooms = {}
rooms[1] = { -- room code }
-- etc...
then you can just

Code: Select all

selectedroom = rooms[math.love.random(#rooms)]

User avatar
Ragzouken
Citizen
Posts: 84
Joined: Fri Aug 10, 2012 7:59 am
Contact:

Re: How to choose renadom map from a list?

Post by Ragzouken » Wed Apr 09, 2014 9:19 am

nuno wrote:

Code: Select all

selectedroom = rooms[math.love.random(#rooms)]
should be

Code: Select all

selectedroom = rooms[love.math.random(#rooms)]

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests