Skip to content

Commit d9de29f

Browse files
committedJun 23, 2014
Clear inventory before setting lists
1 parent 5fb8778 commit d9de29f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
 

‎src/script/lua_api/l_inventory.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,20 @@ int InvRef::l_set_lists(lua_State *L)
271271
if (!inv) {
272272
return 0;
273273
}
274+
275+
// Make a temporary inventory in case reading fails
276+
Inventory *tempInv(inv);
277+
tempInv->clear();
278+
279+
Server *server = getServer(L);
280+
274281
lua_pushnil(L);
275282
while (lua_next(L, 2)) {
276-
const char* listname = lua_tostring(L, -2);
277-
InventoryList *list = inv->getList(listname);
278-
if (list) {
279-
read_inventory_list(L, -1, inv, listname,
280-
getServer(L), list->getSize());
281-
} else {
282-
read_inventory_list(L, -1, inv, listname,
283-
getServer(L));
284-
}
283+
const char *listname = lua_tostring(L, -2);
284+
read_inventory_list(L, -1, tempInv, listname, server);
285285
lua_pop(L, 1);
286286
}
287+
inv = tempInv;
287288
return 0;
288289
}
289290

0 commit comments

Comments
 (0)
Please sign in to comment.