Echo command syntax
-
I was working with the echo syntax to incorporate the ">" & ">>" capabilities and was using the persistentGlobal.g file identified in the "GCode Meta Commands. However, when executing the file I receive the error:
Error: in file macro line 6 column 7: meta command: expected a string expression
file: _TestVar1
M98 P"/sys/scripts/persistentGlobal.g" V"testVar" X"one"
After some back-and-forth, I found the root cause to be that the example had a space the ">" Removing the space resolved the problem. I only noticed this after looking at the earlier examples in the documentation which did not have the additional space where the filename was being provided.
Old code:
var id = param.V ; name of the global variable var value = param.X ; value to save var filepath = "globals/"^{var.id} ; internal file path where the global variable is saved ; Save the global variable as a file so it is persistent echo > {var.filepath} "if exists(global."^{var.id}^")" echo >> {var.filepath} " set global."^{var.id}^" = "^{var.value} echo >> {var.filepath} "else" echo >> {var.filepath} " global "^{var.id}^" = "^{var.value} M98 P{var.filepath} ; load the global variable
Working code:
var id = param.V ; name of the global variable var value = param.X ; value to save var filepath = "globals/"^{var.id} ; internal file path where the global variable is saved ; Save the global variable as a file so it is persistent echo >{var.filepath} "if exists(global."^{var.id}^")" echo >>{var.filepath} " set global."^{var.id}^" = "^{var.value} echo >>{var.filepath} "else" echo >>{var.filepath} " global "^{var.id}^" = "^{var.value} M98 P{var.filepath} ; load the global variable
I just thought I'd pass this along.
Using v3.6 rc1 & rc2 both produced the error.
-
@Gamefanatic3D Are you running in standalone mode or using an SBC?
-
@gloomyandy Stand-alone mode.
-
@Gamefanatic3D that's correct, the syntax described at https://docs.duet3d.com/en/User_manual/Reference/Gcode_meta_commands#echo-command does not permit spaces after the > or >> or >>> symbol.
-
@dc42 Tracking the syntax. However with the example at the bottom of the page not following the syntax it's not clear, so I thought it worth reporting such that either the "Examples of Use" section or the syntax would be updated.
Saving and restoring variables across a reset
- persistentGlobal.g
- loadPersistentGlobal.g
-
@Gamefanatic3D thanks, I have corrected the persistentGlobal.g example.