diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index 134b80287b..0db9a20009 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -858,18 +858,32 @@ SQInteger ScriptList::_get(HSQUIRRELVM vm) SQInteger ScriptList::_set(HSQUIRRELVM vm) { if (sq_gettype(vm, 2) != OT_INTEGER) return SQ_ERROR; - if (sq_gettype(vm, 3) != OT_INTEGER && sq_gettype(vm, 3) != OT_NULL) { - return sq_throwerror(vm, "you can only assign integers to this list"); - } - SQInteger idx, val; + SQInteger idx; sq_getinteger(vm, 2, &idx); - if (sq_gettype(vm, 3) == OT_NULL) { - this->RemoveItem(idx); - return 0; + + /* Retrieve the return value */ + SQInteger val; + switch (sq_gettype(vm, 3)) { + case OT_NULL: + this->RemoveItem(idx); + return 0; + + case OT_BOOL: { + SQBool v; + sq_getbool(vm, 3, &v); + val = v ? 1 : 0; + break; + } + + case OT_INTEGER: + sq_getinteger(vm, 3, &val); + break; + + default: + return sq_throwerror(vm, "you can only assign integers to this list"); } - sq_getinteger(vm, 3, &val); if (!this->HasItem(idx)) { this->AddItem(idx, val); return 0;