Skip to content

Commit

Permalink
Return nil instead of #wesnoth.playlist+1 when the current track is n…
Browse files Browse the repository at this point in the history
…ot on the playlist
  • Loading branch information
CelticMinstrel committed Apr 23, 2017
1 parent 548ecb6 commit c83809e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/scripting/lua_audio.cpp
Expand Up @@ -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());
Expand Down

0 comments on commit c83809e

Please sign in to comment.