table wont work help me pls

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
nineret
Prole
Posts: 2
Joined: Sat Apr 18, 2020 12:58 pm

table wont work help me pls

Post by nineret »

this is a table

Code: Select all

local BlockTable = {
Block1 = {
x = 181,width = 409,y = 220,height = 220},
Block2 = {
x = 9999,width = 9999,y = 462,height = 462},
Block3 = {
x = 9999,width = 9999,y = 9999,height = 9999},
Block4 = {
x = 9999,width = 9999,y = 9999,height = 9999}
}
script I want to run
f

Code: Select all

function love.update(dt)
 move_up_down(dt)

end

Code: Select all

function move_up_down(dt)
  if love.keyboard.isDown("w") then
    for i, block in ipairs(BlockTable) do
       for h=1, block.Block[i] do
    if player.x > BlockTable[i].Block[h].x and player.x < BlockTable[i].Block[h].height and player.y > BlockTable[i].Block[h].y or player.y > ObjectTable[1] then
		player.y = player.y - 100 * dt
  else
    player.y = player.y - 0 * dt
  end end end end end
table wont work ;-;
User avatar
steVeRoll
Party member
Posts: 139
Joined: Sun Feb 14, 2016 1:13 pm

Re: table wont work help me pls

Post by steVeRoll »

If you want a table to be an array, you don't define its entries with names (Block1, Block2) - just put them one after another. So, BlockTable should become this:

Code: Select all

local BlockTable = {
	{
		x = 181,width = 409,y = 220,height = 220},
	{
		x = 9999,width = 9999,y = 462,height = 462},
	{
		x = 9999,width = 9999,y = 9999,height = 9999},
	{
		x = 9999,width = 9999,y = 9999,height = 9999}
}
And in the ipairs loop, you can access the block simply by using the "block" variable, there's no need to index BlockTable manually.

Also, next time please describe your error with more detail. Instead of just "table won't work", specify what the error was and where it happened.
User avatar
nineret
Prole
Posts: 2
Joined: Sat Apr 18, 2020 12:58 pm

Re: table wont work help me pls

Post by nineret »

thank!

but I don't how to reply
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: table wont work help me pls

Post by zorg »

nineret wrote: Thu Apr 23, 2020 11:56 am but I don't how to reply
i mean, you just did... :monocle:
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests