Jump to content
  • Advertisement
Sign in to follow this  
Guy Meh

Finding element inside Lua table

This topic is 3662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to fill a Lua table with (x, y) coordinates, which I'm representing with tables that store a pair of numbers, and later test if a coordinate is in this table. As far as I can tell, there is no built-in search or find function to access values in a table. I've tried inserting my coordinates as keys (myTable[{x, y}] = true) but that only works for references; I can't loop through my x and y values and use a new (x, y) coordinate. Is there a way around this besides writing a search function from scratch?

Share this post


Link to post
Share on other sites
Advertisement
I've never seen one. You're asking to search through a table, and find a matching value, which may be other tables, etc.

Just write a quick one yourself to loop through all the elements in your table and check the "x" and "y" fields.

Share this post


Link to post
Share on other sites
What I ended up doing was convert the coordinates into a string and putting that into the table. When I loop through the x and y values, I convert the current coordinates into a string again.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!