From 57cea4e98cecc7115a67ee78a1d48c1b32f8f6b1 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Thu, 29 May 2025 18:07:19 +0100 Subject: [PATCH] Add: [Script] Auto-convert ObjectType bool to integer when setting values for items in lists via [] --- src/script/api/script_list.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index 70deef82a0..5cdf900b15 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -844,18 +844,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;