allow globals to be overwritten upon definition
-
Hi,
since I use quite a few global variables in my printer definition, I would love to see a the following feature:
At the moment I define all my globals in config.g. As an overview, here are the first lines of this section:
; here we define all global vars ; NOTE: use if !exists() because they could be defined allready and therefore throw an error ; ----- ----- Common variable declarations ----- ----- ; IdlePos if !exists(global.IdlePos) global IdlePos = {-170, 100, 5} else set global.IdlePos = {-170, 100, 5} ; Z lift state if !exists(global.ZisLifted) global ZisLifted = false else set global.ZisLifted = false ; run daemon flag if !exists(global.RunDaemon) global RunDaemon = true else set global.RunDaemon = true ...
As you can see, the need for this if else construct increases the file size quite a bit. Unfortunately, this is necessary to allow config.g to be re-run via M98. Otherwise I would get an error message like this: Error: variable 'global.test' already exists
In order not to change the current default behavior, I would suggest a new keyword that can be inserted after
global
. That would lead to something like this:global override ZisLifted = false
as a shorthand to the functionality of this:
if !exists(global.ZisLifted) global ZisLifted = false else set global.ZisLifted = false
As an alternative, it might be appropriate to change the default behavior so that an existing variable is always overwritten.
In my opinion, both solutions would be an advantage over the current implementation, what do you guys think?
-
@marvineer You don't really need to test for each one, just test for one of them and groupe then creation/setting together...
if !exists(global.global1) global global1 = {1, 2, 3} global global2 = {3, 4, 5} global global3 = "whatever" else set global.global1 = {1, 2, 3} set global.global2 = {3, 4, 5} set global.global3 = "whatever"
Also if these globals are in effect constants (so nothing anywhere else changes the value), then there is no need to set the value if the global(s) already exist.