1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-19 10:22:39 +01:00

Add: [Script] Auto-convert ObjectType bool to integer when setting values for items in lists via [] (#14308)

This commit is contained in:
SamuXarick
2025-10-29 20:18:00 +00:00
committed by GitHub
parent 3b02761302
commit 3ebedecb4a

View File

@@ -854,18 +854,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;