Trouble With Tables [SOLVED]

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
ITISTHEBKID
Prole
Posts: 8
Joined: Sun Nov 11, 2018 9:45 pm

Trouble With Tables [SOLVED]

Post by ITISTHEBKID »

Code: Select all

	function love.load()
	A = {B = 0, C = 0}
	Z  = {A.B = 3,}
	print(Z.A.B)
	end
Why does this code spit out an error?
Last edited by ITISTHEBKID on Sat Nov 17, 2018 8:08 pm, edited 1 time in total.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Trouble With Tables

Post by veethree »

You need to define A as a table inside Z.

Code: Select all

Z  = {A = {B = 3}}
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Trouble With Tables

Post by zorg »

Do note that Z.A.B has absolutely nothing to do with A.B in veethree's solution; they are separate tables.
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.
ITISTHEBKID
Prole
Posts: 8
Joined: Sun Nov 11, 2018 9:45 pm

Re: Trouble With Tables

Post by ITISTHEBKID »

Is there a way to make it so things can go through Z into A?
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Trouble With Tables

Post by pgimeno »

Code: Select all

	A = {B = 0, C = 0}
	Z  = {A = A}
        Z.A.B = 5
        A.C = 7
	print(Z.A.B) -- prints 5
	print(A.B) -- prints 5
	print(Z.A.C) -- prints 7
	print(A.C) -- prints 7
ITISTHEBKID
Prole
Posts: 8
Joined: Sun Nov 11, 2018 9:45 pm

Re: Trouble With Tables

Post by ITISTHEBKID »

Thanks so much!
Post Reply

Who is online

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