Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/GDCore/Project/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void Variable::UnserializeFrom(const SerializerElement& element) {

if (IsPrimitive(type)) {
if (type == Type::String) {
SetString(element.GetStringAttribute("value", "0", "Value"));
SetString(element.GetStringAttribute("value", "", "Value"));
} else if (type == Type::Number) {
SetValue(element.GetDoubleAttribute("value", 0.0, "Value"));
} else if (type == Type::Boolean) {
Expand Down
2 changes: 1 addition & 1 deletion GDJS/Runtime/variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace gdjs {
// Protect against NaN.
if (this._value !== this._value) this._value = 0;
} else if (this._type === 'string') {
this._str = '' + varData.value || '0';
this._str = varData.value !== undefined ? '' + varData.value : '';
} else if (this._type === 'boolean') {
this._bool = !!varData.value;
} else if (this._type === 'structure') {
Expand Down
9 changes: 9 additions & 0 deletions newIDE/app/src/VariablesList/VariablesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,16 @@ const VariablesList: React.ComponentType<{
props.variablesContainer
);
if (!variable) return;
const oldType = variable.getType();
variable.castTo(newType);
// When changing type to String, reset to an empty string.
if (newType === 'string' && oldType === gd.Variable.Number) {
variable.setString('');
}
// When changing type to Number, reset to 0.
if (newType === 'number' && oldType === gd.Variable.String) {
variable.setValue(0);
}
_onChange();
forceUpdate();
},
Expand Down
Loading