Const specific for certain variable only.

Feature requests for future versions of Hollywood can be voiced here

Const specific for certain variable only.

Postby Bugala » 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:
Code: Select all
Const myvariable #ON = 1

Code: Select all
myvariable = #ON

mysecondvariable = #ON

- 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 }



alert = false
foreach (table_checkforalerts, function (key, item)
                                                     if key=#ALERT then alert = true
until alert=true

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.
Posts: 572
Joined: Sun Feb 14, 2010 8:11 pm

Re: Const specific for certain variable only.

Postby SamuraiCrow » Mon Jun 12, 2017 8:03 pm

It sounds like you are trying to describe enumerations. C allows some rather complicated uses and abuses of the "enum" keyword. Or perhaps making a const table would be more appropriate using a perfect hash function of some sort. might be one type of that.
Posts: 50
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 1 guest