Hi,
I'm trying to learn programming by coding a simple puzzle game in LOVE. Right now there are no controls. Anyway, I'm trying to use .png files to create a map by using color codes to denote different parts of the map. While doing so I realized I could use metatables to simplify color equalities by comparing {r,g,b,a} tables at every pixel on the map, which I would later use to draw the appropriate tiles.
I wrote a metamethod for the equality operator which I translated into python to test for validity.(attachment: equalityTesting.txt)
Unfortunately, the equality operator seems to not be working. It never returns true, hence drawing nothing on the screen. (Line 41: maploader.lua; attachment: gameFolder.love)
Comments at the beginning of main.lua may be useful.
Where did I go wrong?
Unable to compare two tables using metatables.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Unable to compare two tables using metatables.
- Attachments
-
- gameFolder.love
- (5.6 KiB) Downloaded 245 times
-
- equalityTesting.txt
- (423 Bytes) Downloaded 201 times
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Unable to compare two tables using metatables.
You're not applying the metatable to the tables in "color". On line 10 of colors.lua use pairs instead of ipairs and it works.
Re: Unable to compare two tables using metatables.
Oh my god. THANK YOU!
On a side note, I had been checking notifications constantly and your reply did not show up. I'm so glad to see that they do not lie about the niceness of this community! Thank you very much once again!
On a side note, I had been checking notifications constantly and your reply did not show up. I'm so glad to see that they do not lie about the niceness of this community! Thank you very much once again!
-
- Citizen
- Posts: 87
- Joined: Tue Dec 30, 2014 6:07 pm
Re: Unable to compare two tables using metatables.
For your particular scenario you can actually go even further with memoization
https://www.lua.org/pil/17.1.html
If you have a color factory that remembers the previous color/tables and returns them when asked for the same ones then you can compare colors using == with no meta tables.
https://www.lua.org/pil/17.1.html
If you have a color factory that remembers the previous color/tables and returns them when asked for the same ones then you can compare colors using == with no meta tables.
Re: Unable to compare two tables using metatables.
I believe you only get notifications if you're quoted, or if you're subscribed to the topic (see the wrench next to "Post Reply")
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 10 guests