From 7d0b7c3009a49526dcdfa5e1a1e6b15002589cf8 Mon Sep 17 00:00:00 2001 From: Ankitkumar Satapara Date: Wed, 29 Apr 2026 14:11:08 +0530 Subject: [PATCH] Fixed variables are not passing the defualt values --- Examples/Nodify.Calculator/Executor.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Examples/Nodify.Calculator/Executor.cs b/Examples/Nodify.Calculator/Executor.cs index 2efd72a..cd7d41e 100644 --- a/Examples/Nodify.Calculator/Executor.cs +++ b/Examples/Nodify.Calculator/Executor.cs @@ -592,6 +592,19 @@ namespace Nodify.Calculator private void ResolveGetVariableNodes(ICollection allNodes, ICollection connections) { + // Seed the variables dictionary with default values from the variable definitions + // so GET nodes return the user-defined default if no SET has been executed yet. + var availableVars = editorViewModel.Calculator.OperationsMenu.AvailableVariables; + foreach (var varInfo in availableVars) + { + if (string.IsNullOrEmpty(varInfo.Title)) continue; + if (!variables.ContainsKey(varInfo.Title) && !string.IsNullOrEmpty(varInfo.DefaultValue)) + { + variables[varInfo.Title] = varInfo.DefaultValue; + OnLogMe?.Invoke($"Variable '{varInfo.Title}' seeded with default value: {varInfo.DefaultValue}"); + } + } + // Find all GET variable nodes (not in flow chain) and populate their output foreach (var node in allNodes) { @@ -606,12 +619,13 @@ namespace Nodify.Calculator // Check if the variable already has a value if (variables.TryGetValue(varName, out var existingVal)) { - outputs[node.NodeId] = existingVal?.ToString() ?? ""; + var strVal = existingVal?.ToString() ?? ""; + outputs[node.NodeId] = strVal; // Set the output connector value for downstream nodes var outConn = node.Output.FirstOrDefault(c => c.Shape != ConnectorShape.Triangle); if (outConn != null) { - if (double.TryParse(existingVal?.ToString(), out double dVal)) + if (double.TryParse(strVal, out double dVal)) outConn.Value = dVal; } OnLogMe?.Invoke($"GET variable '{varName}' resolved to: {existingVal}");