News:

  • September 27, 2026, 10:15:02 PM

Login with username, password and session length

Author Topic: Feature request -- boolean constants  (Read 10500 times)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Feature request -- boolean constants
« on: October 11, 2023, 12:49:07 PM »
I know I have one or two feature requests in regarding SKs, but I don't think I've mentioned this one.   I'd like to have nameable booleans.   MySK = True, etc.   Probably preferable to have them show up as TRUE and FALSE in the docs (cause it'd be obvious it's a bool), but 0 & 1 is fine too.

If easier, less optimal would be ability to cast SKs, so I could have a MySK:0 as a contact.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Feature request -- boolean constants
« Reply #1 on: October 12, 2023, 01:25:00 AM »
So what would this offer that constants named True = 1, False = 0, On = 1, Off = 0, etc won't solve?

However, I've noticed I can't COPY On to C0 for a simple example, so there's another feature request.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Feature request -- boolean constants
« Reply #2 on: October 12, 2023, 08:26:31 AM »
SKs in general do two things as I see it.   (1) Code readibility, where my elevator app is comparing FloorNum with TopFloorSK, vs with '4'.  (2) Easy goof-proof config during startup.  I go change TopFloorSK from 4 to 6 in the definition once and threre's no chance I inadvertently miss one '4' in the code nor change an unrelated '4'.  Plus it's quicker.

Bool SKs would do those same two things to install-specific bools that they do for ints & floats.  Having it recognized by the PLC as a  bool lets me use a contact vs. making it an int and having to do a comparison, etc.  Also, it would lead to cleaner MATH IFs.  "IF(MySK, Exp1, Exp2) + Exp3"

Example case is FeaturedXInstalledSK.  Being able to use a contact vs. 'FeatureXInstalled = 1'.
« Last Edit: October 12, 2023, 08:41:50 AM by Controls Guy »
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Feature request -- boolean constants
« Reply #3 on: October 12, 2023, 08:52:45 AM »
Your MOVE is an example of the issue.  You want to use it as a bool, but the PLC can't help but assume that its an int, and won't do the thing you're trying to do.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Feature request -- boolean constants
« Reply #4 on: October 12, 2023, 09:08:15 AM »
This is what $On and $Off are for.  They are technically memory locations (ST1 and ST2), but the result is the same.

How about an option to use the tags $True $False over $On $Off for those ST bits?  We would need to think through any ramifications, but that may work.  You would still be able to use TRUE/True FALSE/False (whatever) for Symbolic Constant (the dollar sign signifies a system-assigned NN).

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Feature request -- boolean constants
« Reply #5 on: October 12, 2023, 12:48:38 PM »
No, what I was looking for was analogous to the difference between K4 and TopFloorSK.   I don't mind $True/False vs. $On/Off where universal ones can be used, but configuring job-to-job having used $On and $Off is like configuring job to job without numerical SKs (because there's only one $On and one $Off, they're program-wide).   "Is this K4 one of the ones I have to change?   Oops, changed one of the ones that wasn't supposed to", etc.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3847
    • Host Engineering
Re: Feature request -- boolean constants
« Reply #6 on: October 12, 2023, 12:55:21 PM »
I get what you are looking for now.  Let us chew on it.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3626
  • Darth Ladder
Re: Feature request -- boolean constants
« Reply #7 on: October 12, 2023, 03:24:35 PM »
Cool, thank you!   8)
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.