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

[store_time_of_day] throws a lua error in "time over" event, or querying a turn after the scenario's turn limit #6311

Open
virtualghetto opened this issue Nov 19, 2021 · 4 comments
Assignees
Labels
Bug Issues involving unexpected behavior. Lua API Issues with the Lua engine and API.

Comments

@virtualghetto
Copy link

Game and System Information

1.16.1 built from tag 1.16.1. Debian cmake clang++

Describe the bug

[store_time_of_day] throws a lua error when called from inside a time over event.

20211119 11:50:41 error scripting/lua: lua/wml/store_time_of_day.lua:17: bad argument #2 to 'get_time_of_day' (turn number out of range)
stack traceback:
        [C]: in field 'get_time_of_day'
        lua/wml/store_time_of_day.lua:17: in local 'cmd'
        lua/wml-utils.lua:144: in field 'handle_event_commands'
        lua/wml-flow.lua:5: in function <lua/wml-flow.lua:4>

To Reproduce

Add the following to a dummy scenario and click end turn twice.

    turns = 2

    [event]
        name=time over

        [store_time_of_day]
        [/store_time_of_day]
    [/event]
@Wedge009 Wedge009 added Bug Issues involving unexpected behavior. Lua API Issues with the Lua engine and API. labels Nov 19, 2021
@CelticMinstrel
Copy link
Member

Sounds like an off-by-one error somewhere. Either that, or the turn number actually advances to turn 3 during the time over event.

The second possibility could probably be tested by replacing the store_time_of_day tag with something that allows you to determine the current turn number, for example inspect or perhaps a message tag.

@virtualghetto
Copy link
Author

Sounds like an off-by-one error somewhere. Either that, or the turn number actually advances to turn 3 during the time over event.

turn_number does become 3 in time over. This happens in 1.14 as well, but [store_time_of_day] won't throw a lua error there. I'm not sure what time it stores in that case.

The lua error seems to be a 1.16 feature only.

    turns = 2
    [event]
        name=time over

        [store_turns]
        [/store_turns]

        [chat]
            speaker=bug
            message="$turn_number / $turns"
        [/chat]

        [store_time_of_day]
        [/store_time_of_day]
    [/event]

@CelticMinstrel
Copy link
Member

Hmm. The time of day API doesn't allow checking the time in a turn greater than the turn limit. We could allow one turn after, but… we could also just remove that limitation entirely? I don't think there's any actual reason to disallow extrapolating the schedule beyond the turn limit… especially since the turn limit can be changed.

@mattsc
Copy link
Member

mattsc commented Jun 9, 2022

Yeah. I'd suggest removing the limitation altogether. I can easily think of use cases for which querying the ToD beyond the turn limit makes sense.

@CelticMinstrel CelticMinstrel self-assigned this Jun 10, 2022
@stevecotton stevecotton changed the title [store_time_of_day] throws a lua error [store_time_of_day] throws a lua error in "time over" event, or querying a turn after the scenario's turn limit Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues involving unexpected behavior. Lua API Issues with the Lua engine and API.
Projects
None yet
Development

No branches or pull requests

4 participants