From a Matrix conversation today, for posterity:
Zughy asks:
I can't recall, is there a function to check whether a table is a position?
and adds:
I've got a function passing a table and I want to make sure that the table is a position
Blockhead (I) first attempted to answer:
not an obvious one in the API the best I can think to do is reverse-engineered from reading the Lua builtin code:
getmetatable(t) == vector.metatable
vectors and positions being basically the same thing (I eagerly await everyone's comments on how they are not)
LMD (appgurueu) answers:
vector.check(v) [api ref]
I then reply:
which as is turns out.. has an implementation that checks the same metatable I mentioned
it pays to read more :) [referring to reading documentation to find what you are after, rather than blindly using Ctrl+F]
Further comments:
Vectors and positions both use the same table format in Minetest, which is constructed with vector.new and sets its metatable to the table available at vector.metatable. Thankfully you do not need to know this detail and can use the library function vector.check which takes care of the details for you. You can use this kind of check to change behaviour based on the provided data type (like how vector.add can work with vectors or scalars), or reject invalid input to your APIs.
[Solved] How do I check if a table is a position?
- Blockhead
- Member
- Posts: 1624
- Joined: Wed Jul 17, 2019 10:14
- GitHub: Montandalar
- IRC: Blockhead256
- In-game: Blockhead Blockhead256
- Location: Land Down Under
- Contact:
[Solved] How do I check if a table is a position?
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂
- SuperStarSonic
- Member
- Posts: 160
- Joined: Fri Oct 14, 2022 20:30
- GitHub: Python-Sargent
- In-game: SuperStarSonic
- Location: Earth (may be out of date)
Re: [Solved] How do I check if a table is a position?
You could also use minetest.is_pos(position) if you didn't want to figure the vector API out.
- LMD
- Member
- Posts: 1386
- Joined: Sat Apr 08, 2017 08:16
- GitHub: appgurueu
- IRC: appguru[eu]
- In-game: LMD
- Location: Germany
- Contact:
Re: [Solved] How do I check if a table is a position?
There is no minetest.is_pos; grepping the API docs, the C sources and the Lua sources (builtin) yields no result.SuperStarSonic wrote: ↑Mon Mar 13, 2023 03:23You could also use minetest.is_pos(position) if you didn't want to figure the vector API out.
- SuperStarSonic
- Member
- Posts: 160
- Joined: Fri Oct 14, 2022 20:30
- GitHub: Python-Sargent
- In-game: SuperStarSonic
- Location: Earth (may be out of date)
Re: [Solved] How do I check if a table is a position?
That is odd, maybe I used something like it and forgot the name, I'm sorry.
- Blockhead
- Member
- Posts: 1624
- Joined: Wed Jul 17, 2019 10:14
- GitHub: Montandalar
- IRC: Blockhead256
- In-game: Blockhead Blockhead256
- Location: Land Down Under
- Contact:
Re: [Solved] How do I check if a table is a position?
SuperStarSonic wrote: ↑Mon Mar 13, 2023 03:23You could also use minetest.is_pos(position) if you didn't want to figure the vector API out.
By the time you've reached this forum thread, it would be kind of silly to ignore the advice contained in it, don't you think? Don't you also think that if that function were real and not made up, then that would be the answer given? I'm really not sure what you were trying to achieve here.SuperStarSonic wrote: ↑Mon Mar 13, 2023 16:44That is odd, maybe I used something like it and forgot the name, I'm sorry.
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂
- rubenwardy
- Moderator
- Posts: 6972
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: [Solved] How do I check if a table is a position?
Did you use ChatGPT to find out that function? It likes to make them up
- SuperStarSonic
- Member
- Posts: 160
- Joined: Fri Oct 14, 2022 20:30
- GitHub: Python-Sargent
- In-game: SuperStarSonic
- Location: Earth (may be out of date)
Re: [Solved] How do I check if a table is a position?
Whoa, that's creepy, that looks like I may have come across a bot-scam in a non-trusted site!
What's odd is I think it was on a forum, so I don't think it would of been that convincing.
I know about the fake articles, but aren't they based off of real data?
What's odd is I think it was on a forum, so I don't think it would of been that convincing.
I know about the fake articles, but aren't they based off of real data?
Who is online
Users browsing this forum: No registered users and 12 guests