diff options
author | kwolekr <kwolekr@minetest.net> | 2013-04-21 12:55:46 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-04-21 12:55:46 -0400 |
commit | 14ba94ad6a0e2176106af08e41d99ad81b03e9e4 (patch) | |
tree | 55df22ba465865fce8a0e326c1962b7a149d9e38 | |
parent | 03868ff8e1bcdcc831b8bd845b8ea7961f7ea1c8 (diff) | |
download | minetest-14ba94ad6a0e2176106af08e41d99ad81b03e9e4.tar.gz minetest-14ba94ad6a0e2176106af08e41d99ad81b03e9e4.tar.bz2 minetest-14ba94ad6a0e2176106af08e41d99ad81b03e9e4.zip |
Fix hud_change stat argument retrieval
-rw-r--r-- | src/scriptapi_object.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index 3d56aad29..9152c9eb3 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -788,15 +788,17 @@ int ObjectRef::l_hud_change(lua_State *L) if (player == NULL) return 0; - u32 id = -1; - if (!lua_isnil(L, 2)) - id = lua_tonumber(L, 2); - - HudElementStat stat = (HudElementStat)getenumfield(L, 3, "stat", - es_HudElementStat, HUD_STAT_NUMBER); - + u32 id = !lua_isnil(L, 2) ? lua_tonumber(L, 2) : -1; if (id >= player->hud.size()) return 0; + + HudElementStat stat = HUD_STAT_NUMBER; + if (!lua_isnil(L, 3)) { + int statint; + std::string statstr = lua_tostring(L, 3); + stat = string_to_enum(es_HudElementStat, statint, statstr) ? + (HudElementStat)statint : HUD_STAT_NUMBER; + } void *value = NULL; HudElement *e = player->hud[id]; @@ -832,7 +834,7 @@ int ObjectRef::l_hud_change(lua_State *L) e->dir = lua_tonumber(L, 4); value = &e->dir; } - + get_server(L)->hudChange(player, id, stat, value); lua_pushboolean(L, true); |