Select Active / Switch Case
ryanww
Junior Member
So in either Select Active or Switch Case, can multiple instances happen? I would guess more so with Select Active..
Here is an example:
X=1, Y=1, Z=0
SELECT
{
ACTIVE (X):
{DO SOMETHING}
ACTIVE (Y):
{DO SOMETHING ELSE}
ACTIVE (Z):
{DO SOMETHING ELSE}
}
Would both the commands in X and Y execute assuming both statments were true?
Thanks
Here is an example:
X=1, Y=1, Z=0
SELECT
{
ACTIVE (X):
{DO SOMETHING}
ACTIVE (Y):
{DO SOMETHING ELSE}
ACTIVE (Z):
{DO SOMETHING ELSE}
}
Would both the commands in X and Y execute assuming both statments were true?
Thanks
Comments
-
Each ACTIVE statement could be looking different variables, so each one could be true. Each one that is will execute. On a SWITCH/CASE, you are only looking at one variable. Only one (or none) of the case's can be true at the same time.
Kevin D. -
Cool, thats what I thought.. Just wanted to make sure..
Thanks -
No. In Amxland there is no fall-thru only the first true condition is executed the rest are ignored.
So for easy examples you could do:
Select
{
Active ((X) || (Y) || (Z)): Do Stuff if you want the same result
}
OR
If (X) Do thing #1
If (Y) Do thing #2
If (Z) Do thing #3 -
Aw.. that sucks.. Well that would be a cool command for the future of AMX.. It would come in handy for me a few times.. Just a few less things to do..
-
I stand corrected. Never had a need for the first example but always assumed based on the wording. I almost ran a test program because I wasn't 100%.. Damn.
Kevin D. -
Man, it's right there in the help file too..The SELECT?ACTIVE statement provides a programming structure for selective execution of code blocks based on the evaluation of a series of conditions. The first block whose ACTIVE condition evaluates to true is executed; the remaining blocks are ignored. If no ACTIVE condition evaluates to true, no statements are executed.
Kevin D -
X=1, Y=1, Z=0 IF(X) {DO SOMETHING} IF(Y) {DO SOMETHING ELSE} IF(Z) {DO SOMETHING ELSE}
This will allow more than one state to fire in the same statement -
switch...case
It should also be noted switch...case in Netlinx has a subtle difference compared to every other language that structure appears.switch(nVar){ case 1: SEND_COMMAND dvDev, 'A'; break; case 2: case 3: case 4: case 5: SEND_COMMAND dvDev, 'B'; break; case 6: SEND_COMMAND dvDev, 'C'; default: SEND_COMMAND dvDev, 'D'; break; }nVar=1 only triggers A. nVar=2, 3, 4, or 5 will all trigger B. However, you would expect (if you came from other languages) that nVar=6 would trigger C and D, but no, it only triggers C.
The case only falls through in the case of a totally empty case. The break keyword in a switch...case is merely cosmetic in this langauge. -
Well I am looking to do the opposite of that.. well kind of.. I just want one Select Active set but if say like multiple variables are true, it will fire those, but not necessarily together..
-
mpullin wrote:... nVar=2, 3, 4, or 5 will all trigger B....
Alternatively if you want nVar=2 to do nothing you need to add curly brackets to the code:
case 2: {}
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums