Dont even know what to google

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
akopyl
Prole
Posts: 21
Joined: Fri Jun 27, 2014 1:20 pm

Dont even know what to google

Post by akopyl »

What do I put instead of *numbers 1-8* for it to work? Or is there an another way of doing this?

Code: Select all

if level.rComplete[*numbers 1-8*] and level.cComplete[*numbers 1-8*] then
	level.complete = true
else
	level.complete = false
end
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Dont even know what to google

Post by MadByte »

I can't see what you want to know from your tiny bit of code. You need to explain what you want to accomplish,
otherwise I just can guess.

- What kind of game are you working on?
- What is "rComplete" and "cComplete" ?

Edit Just a guess:

Code: Select all

function isLevelCompleted()
  for _, goal in ipairs(level.rComplete) do
    if not goal then return false end
  end
  for _, goal in ipairs(level.cComplete) do
    if not goal then return false end
  end
  return true
end

User avatar
akopyl
Prole
Posts: 21
Joined: Fri Jun 27, 2014 1:20 pm

Re: Dont even know what to google

Post by akopyl »

MadByte wrote:I can't see what you want to know from your tiny bit of code. You need to explain what you want to accomplish,
otherwise I just can guess.

- What kind of game are you working on?
- What is "rComplete" and "cComplete" ?
I want to have something that would do this:

Code: Select all

if level.rComplete[1] and level.rComplete[2] and level.rComplete[3] and level.rComplete[4] and level.rComplete[5] and level.rComplete[6] and level.rComplete[7] and level.rComplete[8] and level.cComplete[1] and level.cComplete[2] and level.cComplete[3] and level.cComplete[4] and level.cComplete[5] and level.cComplete[6] and level.cComplete[7] and level.cComplete[8] then
   level.complete = true
else
   level.complete = false
end
It is a puzzle game and you can complete it if you have completed all rows (level.rComplete) and columns (level.cComplete).
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Dont even know what to google

Post by MadByte »

I guess you should try to use a a multi-dimentional array for that. The level table would look like this:

Code: Select all

--Example Time --
level.data = {
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
  {1, 1, 2, 2, 1, 1, 2, 1, 2, 2},
}
You can interate through that with this piece of code:

Code: Select all

  for x = 0, level.width do
    for y = 0, level.height do
      if level.data[x][y] == 1 then 
        -- do stuff
      end
    end
  end
Now, if you want to check if each cell is i.e 1 (imagine this is the "levelCompleted" condition) do this:

Code: Select all

function checkCompleted()
  for x = 0, level.width do
    for y = 0, level.height do
      if level.data[x][y] ~= 1 then return end
    end
  end
  return true
end
Here is the full example.
levelExample.love
Answer to your question could look like that:

Code: Select all

function checkComplete()
  --Columns--
  for i=1, #level.cComplete do
    if not level.cComplete[i] then return false
  end
  
  --Rows--
  for i=1, #level.rComplete do
    if not level.rComplete[i] then return false
  end
  return true
end
level.complete is not needed.
Rickton
Party member
Posts: 128
Joined: Tue Mar 19, 2013 4:59 pm
Contact:

Re: Dont even know what to google

Post by Rickton »

If you know it's always going to be 8x8, you can keep it pretty simple:

Code: Select all

level.complete = true
for i = 1,8,1 do
 if not level.rComplete[i] or not level.cComplete[i] then
  level.complete = false
  break
 end
end
Possession - Escape from the Nether Regions, my roguelike made in LÖVE for the 2013 7-Day Roguelike Challenge
And its sequel, simply called Possession , which is available on itch.io or Steam, and whose engine I've open-sourced!
User avatar
akopyl
Prole
Posts: 21
Joined: Fri Jun 27, 2014 1:20 pm

Re: Dont even know what to google

Post by akopyl »

Rickton wrote:If you know it's always going to be 8x8, you can keep it pretty simple:

Code: Select all

level.complete = true
for i = 1,8,1 do
 if not level.rComplete[i] or not level.cComplete[i] then
  level.complete = false
  break
 end
end
Wow, cant believe I missed such an obvious solution. Thank you a lot! Works perfectly fine for me.
garcia1000
Prole
Posts: 34
Joined: Sat Nov 28, 2015 5:54 am

Re: Dont even know what to google

Post by garcia1000 »

If you have tables of varying lengths, you can also replace "for i = 1, 8" with "for i = 1, #level.rComplete" or similar.
Post Reply

Who is online

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