Big Oops!
jjames
AMX Sustaining Engineer
I just thought I'd share with everyone a mistake I made that sent me on a goose chase on trying to find the culprit. In my DEFINE_PROGRAM section, I had a function being called that returned a value. Here's a snippet:
After about 10 minutes looking at it, it finally clicked! So to fix the problem I created a STACK_VAR in the begining of the function and used that for the FOR loop. A stupid mistake on my part, but I just thought I'd share my embarassing moment in programming in hopes that others will at least learn from my mistake. Talk about a BIG OOPS!
FOR (nLOOP=1;nLOOP<=LENGTH_ARRAY(dv_TP);nLOOP++)
{
// Camera select feedback
FOR(nLOOP1 = 1;nLOOP1<=LENGTH_ARRAY(nCAMERA_BTNS);nLOOP1++)
[dv_TP[nLOOP],nCAMERA_BTNS[nLOOP1]] = (nCAM_SEL[nLOOP][fnGET_ROOM(nLOOP)] = nLOOP1)
}
Well, the panels can control multiple rooms so I need to know which room it was in. I could have used a simple room select variable, to keep track, but I was trying something new. Anyway... here's the function code:
DEFINE_FUNCTION INTEGER fnGET_ROOM (* Get which room is being controlled */
(INTEGER nPANEL)
{
FOR(nLOOP = 1; nLOOP <= 5; nLOOP++)
{
IF(nPNL_AV[nPANEL] == nAV_ZONE_MAP[nPANEL][nLOOP])
{
RETURN nLOOP;
BREAK;
}
}
}
Can anyone spot the culprit right away? It took me a little bit to actually find it. I'm passing a variable into the function (nLOOP), and the variabled used for the FOR loop is ... nLOOP. I didn't even think about the variable getting used in multiple places at the "same" time. Well, here's the thing: it didn't cause any runtime errors, or anything like that. I was stuck! I couldn't even "pause" the program in debug. I figured it had to be something in the DEFINE_PROGRAM, so I started commenting things out and looking to see what could have messed up my program.After about 10 minutes looking at it, it finally clicked! So to fix the problem I created a STACK_VAR in the begining of the function and used that for the FOR loop. A stupid mistake on my part, but I just thought I'd share my embarassing moment in programming in hopes that others will at least learn from my mistake. Talk about a BIG OOPS!
Comments
-
Whoops! Must have been asleep for that thread.
-
One way to avoid that particular trap is to name local variables and global variables differently, and to have as few global variables as possible.
My local variables all have "My" in their name and function call arguments all have "Arg" in their name. Globals have neither.define_function Something( nArgSomething) { stack_var integer nMySomething }
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