From c5c1901d38abc4e6445b5ad94b534e9f2e2d4e46 Mon Sep 17 00:00:00 2001 From: D8H Date: Tue, 16 Jun 2026 12:50:14 +0200 Subject: [PATCH] Fix the type of variables added from the drop-down menu (#8725) --- .../ParameterFields/VariableField.js | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js b/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js index d40d5cef29..3547cfe27d 100644 --- a/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js +++ b/newIDE/app/src/EventsSheet/ParameterFields/VariableField.js @@ -331,20 +331,6 @@ export default (React.forwardRef( [updateAutocompletions] ); - const isSwitchableInstruction = - instruction && - gd.VariableInstructionSwitcher.isSwitchableVariableInstruction( - instruction.getType() - ); - const variableType = - project && instruction && isSwitchableInstruction - ? gd.VariableInstructionSwitcher.getVariableTypeFromParameters( - project.getCurrentPlatform(), - projectScopedContainersAccessor.get(), - instruction - ) - : null; - const openVariableEditor = React.useCallback( () => { if (!onOpenDialog) { @@ -362,10 +348,16 @@ export default (React.forwardRef( shouldCreate: !!fieldCurrentValue && !isRootVariableDeclared(fieldCurrentValue, variablesContainers), - variableType: getVariableTypeName(variableType), + variableType: instruction + ? getVariableTypeName( + gd.VariableInstructionSwitcher.getSwitchableInstructionVariableType( + instruction.getType() + ) + ) + : 'number', }); }, - [onChange, onOpenDialog, value, variableType, variablesContainers] + [instruction, onChange, onOpenDialog, value, variablesContainers] ); const openParameterEditor = React.useCallback( @@ -386,7 +378,13 @@ export default (React.forwardRef( fieldCurrentValue, variablesContainers ), - variableType: getVariableTypeName(variableType), + variableType: instruction + ? getVariableTypeName( + gd.VariableInstructionSwitcher.getSwitchableInstructionVariableType( + instruction.getType() + ) + ) + : 'number', }); }, [ @@ -394,7 +392,7 @@ export default (React.forwardRef( value, onChange, variablesContainers, - variableType, + instruction, ] ); @@ -465,6 +463,20 @@ export default (React.forwardRef( ? t`This variable has the same name as an object. Consider renaming one or the other.` : null; + const isSwitchableInstruction = + instruction && + gd.VariableInstructionSwitcher.isSwitchableVariableInstruction( + instruction.getType() + ); + const variableType = + project && instruction && isSwitchableInstruction + ? gd.VariableInstructionSwitcher.getVariableTypeFromParameters( + project.getCurrentPlatform(), + projectScopedContainersAccessor.get(), + instruction + ) + : null; + const needManualTypeSwitcher = isSwitchableInstruction && variableType !== gd.Variable.Number &&