It is possible to create variables in Vizzy at runtime by specifying either a string literal or more complex expression on the left-hand side of the "Set to ." A somewhat more detailed explanation, including screenshots and use cases, can be found in my Steam guide, here: https://steamcommunity.com/sharedfiles/filedetails/?id=3033402620
VizzyCode doesn't support this, unfortunately. I'm not sure if it is really feasible to add support for variables declared in this way -- C# doesn't really support expressions on the left hand side of an assignment operator -- but it sure would be nice... :)
A craft file that illustrates the problem can be found here:
https://www.simplerockets.com/c/M4032b/Space-Port-Esperanza-Heavy-Launcher-VizzyGL-required (as the name implies, this version requires the VizzyGL mod be installed to run the code -- but, of course, this isn't required to simply view the Vizzy code, although VizzyCode will generate errors and fail to parse parts of the "Docking Autopilot" code, which is not relevant to this feature request).
An example can be seen in "var Find_Approach_After_Applying = Vz.DeclareCustomInstruction("Find Approach After Applying" In the later custom instruction, the code starts with:
Closest_Approach_Current_TA = Current_TA;
Closest_Approach_Passive_TA = Passive_TA;
var = Time_Since_PE_From_True_Anomaly(Current, Closest_Approach_Current_TA);
var = Time_Since_PE_From_True_Anomaly(Passive, Closest_Approach_Passive_TA);
var = 0;
var = 600;
var = -180;
var = 0;
var = 0;
var = 0;
Starting with the 3rd line, the names of the variables are omitted -- because they are defined as string literals, instead of the standard "green block" variables.
More problematic is this block of code:
var Calculate_Orbital_Parameters_From_State_Vector_At_Planet = Vz.DeclareCustomInstruction("Calculate Orbital Parameters From State Vector At Planet", "in_Prefix_Str", "inPCIPosition", "inPCIVelocity", "inPlanet").SetInstructions((in_Prefix_Str, inPCIPosition, inPCIVelocity, inPlanet) =>
{
var = Vz.ListIndex(Planet_Names, inPlanet);
var = Vz.Time.MissionTime();
var = (Orbital_Parameter_G * Vz.Planet(inPlanet).Mass());
var = Vz.ExactEval("cross(v:inPCIPosition, v:inPCIVelocity)");
var = Vz.RawXmlEval(@"<EvaluateExpression style=""evaluate-expression""><StringOp op=""join"" style=""join""><Constant text=""( cross(v:inPCIVelocity, v:"" /><Variable list=""false"" local=""true"" variableName=""in_Prefix_Str"" /><Constant text=""_h_PCI_Vector) / "" /><Variable list=""false"" local=""true"" variableName=""in_Prefix_Str"" /><Constant text=""_Mu) - normalize(v:inPCIPosition)"" /><Constant text="""" /></StringOp></EvaluateExpression>");
Again, the variable names are omitted -- but in this case, the variable name is actually an expression (specifically the parameter "In_Prefix_Str" is concatenated with a string literal, such as "e_PCI") to generate a variable name in the form of "_<Variable_Name>".
Any hope in adding functionality to the application to deal with this kind of code? There are signficant advantages to using these sorts of adhoc variables -- the biggest of which is that they don't appear in the green block variable list, which makes the list much more useful when you have hundreds of variables to keep track of.
Edited to add: The issue is 100% of the left hand side of the assignment operator. Variables defined in this adhoc manner can only be accessed via fUNK expressions, which VizzyCode already handles properly.
It is possible to create variables in Vizzy at runtime by specifying either a string literal or more complex expression on the left-hand side of the "Set to ." A somewhat more detailed explanation, including screenshots and use cases, can be found in my Steam guide, here: https://steamcommunity.com/sharedfiles/filedetails/?id=3033402620
VizzyCode doesn't support this, unfortunately. I'm not sure if it is really feasible to add support for variables declared in this way -- C# doesn't really support expressions on the left hand side of an assignment operator -- but it sure would be nice... :)
A craft file that illustrates the problem can be found here:
https://www.simplerockets.com/c/M4032b/Space-Port-Esperanza-Heavy-Launcher-VizzyGL-required (as the name implies, this version requires the VizzyGL mod be installed to run the code -- but, of course, this isn't required to simply view the Vizzy code, although VizzyCode will generate errors and fail to parse parts of the "Docking Autopilot" code, which is not relevant to this feature request).
An example can be seen in "var Find_Approach_After_Applying = Vz.DeclareCustomInstruction("Find Approach After Applying" In the later custom instruction, the code starts with:
Starting with the 3rd line, the names of the variables are omitted -- because they are defined as string literals, instead of the standard "green block" variables.
More problematic is this block of code:
Again, the variable names are omitted -- but in this case, the variable name is actually an expression (specifically the parameter "In_Prefix_Str" is concatenated with a string literal, such as "e_PCI") to generate a variable name in the form of "_<Variable_Name>".
Any hope in adding functionality to the application to deal with this kind of code? There are signficant advantages to using these sorts of adhoc variables -- the biggest of which is that they don't appear in the green block variable list, which makes the list much more useful when you have hundreds of variables to keep track of.
Edited to add: The issue is 100% of the left hand side of the assignment operator. Variables defined in this adhoc manner can only be accessed via fUNK expressions, which VizzyCode already handles properly.