Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Variables from Item Def/Definitions #14644

Closed
TubberPupper opened this issue May 12, 2024 · 0 comments · Fixed by #14675
Closed

Removing Variables from Item Def/Definitions #14644

TubberPupper opened this issue May 12, 2024 · 0 comments · Fixed by #14675
Labels
Feature request Issues that request the addition or enhancement of a feature @ Script API

Comments

@TubberPupper
Copy link

TubberPupper commented May 12, 2024

Problem

Sorry if this is a duplicate or isn't formatted properly. I looked for a tiny bit to see if there was a thread opened by appgurueu but I couldn't find one, and this is my first time using GitHub

A thread I opened a few weeks ago https://forum.minetest.net/viewtopic.php?t=30405 went into detail about how to remove functions from an Item's definition. Was told I should open an issue about it by LMD aka @appgurueu :D

There is no official engine function or way (to my knowledge) to remove an unwanted variable - such as "on_use" in this case. Currently I set it to false as a method of committing to this - but this isn't an officially supported way of doing such.

Solutions

Two solutions were proposed by appgurueu and with comments by @Montandalar (BlockHead)

appgurueu's solutions:

I think we should have a way to let override_item delete fields, that definitely seems like a legitimate feature to me. One way to implement this could be using a special, unique minetest.nil_placeholder (could be a userdatum) which could be used instead of false (the problem with false is that it does not work for fields which support booleans; for other fields it's fine however). Or adding another parameter with a list of fields to be deleted?

Montandalar's comment;

I think I like the delete-list better because it extends the API with an extra argument - of course, there may be weird code out there using an extra argument already, because you should expect the unexpected, but that's not really a supported use case. I like the delete-list because doesn't have a magic userdata* value which is probably what would be needed, and also would not be present in older versions whereas the delete-list would pass through and basically be ignored. I suppose that makes it a question of crash vs no crash for a bit of code that doesn't check for compatibility of what it is about to use.

The probably best solution would be to go with the second solution that appgurueu suggested: another parameter - a table of indexes to be removed. But I imagine both solutions could work out just as well?

Alternatives

Well as I mention in the problem, I currently use "false" as a way to modify a function variable so that it is not used.

Additional context

Just be sure to check https://forum.minetest.net/viewtopic.php?t=30405 for anything extra :D

@TubberPupper TubberPupper added the Feature request Issues that request the addition or enhancement of a feature label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Issues that request the addition or enhancement of a feature @ Script API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants