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

Undocumented minetest.get_gametime() returning nil at init time #13882

Closed
gd2shoe opened this issue Oct 11, 2023 · 2 comments · Fixed by #14047
Closed

Undocumented minetest.get_gametime() returning nil at init time #13882

gd2shoe opened this issue Oct 11, 2023 · 2 comments · Fixed by #14047
Labels
Bug Issues that were confirmed to be a bug @ Documentation good first issue

Comments

@gd2shoe
Copy link

gd2shoe commented Oct 11, 2023

Minetest version

Minetest 5.7.0 (Windows)
Using Irrlicht 1.9.0mt10
Using LuaJIT 2.1.0-beta3
BUILD_TYPE=Release
RUN_IN_PLACE=1
USE_CURL=1
USE_GETTEXT=1
USE_SOUND=1
STATIC_SHAREDIR="."
STATIC_LOCALEDIR="locale"

Active renderer

No response

Irrlicht device

No response

Operating system and version

Windows 10

CPU model

AMD FX 6100

GPU model

No response

OpenGL version

No response

Summary

Very simply, I was experimenting to see if minetest.get_gametime() could be useful, and my code exploded. Turns out, it's returning nil. (or at the least, type(minetest.get_gametime())==nil.)

Discovered the issue when trying to subtract one timestamp from another. I wasn't aware of #10221. Still, subtracting one integer from another shouldn't cause problems.

Occurs in minetest_game, both stable-5 and main (if this makes any difference).

Steps to reproduce

assert(minetest.get_gametime(), 'get_gametime should be a number of seconds')

2023-10-11 02:48:38: ERROR[Main]: ModError: Failed to load and run script from C:\local\opt\minetest-5.7.0-win64\bin..\mods\sane_liquid\init.lua:
2023-10-11 02:48:38: ERROR[Main]: ...pt\minetest-5.7.0-win64\bin..\mods\sane_liquid\init.lua:159: get_gametime should be a number of seconds
2023-10-11 02:48:38: ERROR[Main]: stack traceback:
2023-10-11 02:48:38: ERROR[Main]: [C]: in function 'assert'
2023-10-11 02:48:38: ERROR[Main]: ...pt\minetest-5.7.0-win64\bin..\mods\sane_liquid\init.lua:159: in main chunk

@gd2shoe gd2shoe added the Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible label Oct 11, 2023
@sfan5
Copy link
Member

sfan5 commented Oct 11, 2023

Works fine for me, make sure you're not calling it before during init time of the mods.

@Zughy Zughy added Action / change needed Code still needs changes (PR) / more information requested (Issues) @ Script API labels Oct 11, 2023
@gd2shoe
Copy link
Author

gd2shoe commented Oct 11, 2023

That explains it. This is a documentation issue.
(and arguably, a missing feature)

I was looking to use it in an ABM for interval monitoring, but I was initializing the mod timestamp during init. I confirm that it does work in the ABM and on_step so long as I'm not subtracting the timestamp I got during init.

Conceptually speaking, it makes sense for get_gametime() to be available during init. If someone is desperate, and knows to look for it, they can always pull it out of world/env_meta.txt. But I don't think they should have to. A mock function during init might be appreciated by some. I still can't use it because of #10221, which I think is a bigger issue.

That brings up a broader question though: Are there other functions that are not available during init, but where the doc doesn't specify? get_gametime() is in the Environment access section. Should that section have a warning? (like Global callback registration functions does -- "Call these functions only at load time!")

@Zughy Zughy added Bug Issues that were confirmed to be a bug @ Documentation and removed Action / change needed Code still needs changes (PR) / more information requested (Issues) Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible labels Oct 11, 2023
@Zughy Zughy changed the title minetest.get_gametime() returns nil Undocumented minetest.get_gametime() returning nil at init time Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Documentation good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants