diff --git a/src/scripting/lua_audio.cpp b/src/scripting/lua_audio.cpp index 52160e5c9bfc..5cb47b52f6de 100644 --- a/src/scripting/lua_audio.cpp +++ b/src/scripting/lua_audio.cpp @@ -63,7 +63,15 @@ static int impl_music_get(lua_State* L) { push_track(L, sound::get_current_track()); return 1; } - return_int_attrib("current_i", sound::get_current_track() + 1); + if(strcmp(m, "current_i") == 0) { + size_t i = sound::get_current_track(); + if(i == sound::get_num_tracks()) { + lua_pushnil(L); + } else { + lua_pushinteger(L, i + 1); + } + return 1; + } // This calculation reverses the one used in [volume] to get back the relative volume level. // (Which is the same calculation that's duplicated in impl_music_set.) return_float_attrib("volume", sound::get_music_volume() * 100.0f / preferences::music_volume());