Question for tables and variables :3

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.
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Question for tables and variables :3

Post by Volgoza »

Hm hm. )
Ranguna259 wrote:OOH now I see what he wants :crazy: (maybe)
So close. :)

I write decision before (at screenshot).
I have tables (example):

Code: Select all

SomeTable = {}
SomeTable_1 = {}
SomeTable_2 = {}
And i have talbe where i keep all my variables:

Code: Select all

MoreSomeTable = {}
MoreSomeTable[1] = {name = "SomeTable"}
MoreSomeTable[2] = {name = "SomeTable_1"}
MoreSomeTable[3] = {name = "SomeTable_2}"
And i have code, where i move object with coursor mouse and when MouseX and MouseY at coordinates objects of MoreSomeTable i need add value in table. Table names as MoreSomeTable[1].name ...
See? ))

Next: Assume that I have add in table value as i clicked. (Example)

Code: Select all

function love.mousepressed(x, y, button)
if button == "l" then
for i,v in ipairs (MoreSomeTable) do 
table.insert (v.name, 1)
end
end
end
But i can't write v.name, because v.name in this case == "string".

But i can create not 3 tables SomeTable... but create table SomeTable = {} and 3 tables in this table:

Code: Select all

SomeTable = {}
SomeTable.SomeTable = {}
SomeTable.SomeTable_1 = {}
SomeTable.SomeTable_2 = {}
And this code work now:

Code: Select all

function love.mousepressed(x, y, button)
if button == "l" then
for i,v in ipairs (MoreSomeTable) do 
table.insert (MoreSomeTable[v.name], 1)
end
end
end
Because MoreSomeTable == table and v.name insert string value and i get name table == MoreSomeTable.MoreSomeTable...

Clearly explained?
Again sorry for my english. ^_^
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Question for tables and variables :3

Post by Ranguna259 »

Well.. you fixed the problem, all you need to do is to change the string into a table value
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Question for tables and variables :3

Post by Volgoza »

Yes. I did it later :D

But my example sooooo good and extraordinary... and through the ass :awesome: :awesome:
Post Reply

Who is online

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