Const specific for certain variable only.
Posted: Sun Jun 11, 2017 3:45 pm
I was wondering how hard would it be to make Consts that would only work with certain Variables?
An Example of what I am after:
Result:
- 1
- error
Idea behind this is Triple reason.
First of all, to avoid hitting reserved words. For example using something like #ON or #OFF is soemthing that I would be afraid of using since they could easily become reserved in future Hollywood versions (unless they already are).
Second is, that there can sometimes be situations when it could be handy, two silly examples that will however give you the idea:
And third is that something like #ON and #OFF could be useful at many places, but their numerical values might differ, for example if there are more states than just ON and OFF.
An Example of what I am after:
Code: Select all
Const myvariable #ON = 1
Code: Select all
myvariable = #ON
depbugprint(myvariable)
mysecondvariable = #ON
debugprint(mysecondvariable)
- 1
- error
Idea behind this is Triple reason.
First of all, to avoid hitting reserved words. For example using something like #ON or #OFF is soemthing that I would be afraid of using since they could easily become reserved in future Hollywood versions (unless they already are).
Second is, that there can sometimes be situations when it could be handy, two silly examples that will however give you the idea:
Code: Select all
const switch1 #ON = 1
const switch2 #ON = 0
switch1 = #ON
switch2 = #ON
Code: Select all
const defcon #ALARM = 5
const microwave #ALARM = 0
table_checkforalerts = { defcon = 1, microwave = 100 }
Repeat
defcon=defcon+1
microwave=microwave-1
alert = false
foreach (table_checkforalerts, function (key, item)
if key=#ALERT then alert = true
endfunction)
until alert=true
debuprint("ALERT!")