Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: TEMP persistence thru recursion? Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: January 23 2009 at 07:55 | IP Logged Quote GadgetGuy

I have a macro that tests a device and if it receives a "bad" answer waits 5 seconds and tries again.

To keep from creating an infinite loop I want to use an index counter (I'm currently doing this with a GLOBAL var but since there will be several of these test and retry macros I don't want to proliferate GLOBAL vars).

Can I use a LOCAL or TEMP var for my index? The PH User Manual indicates these vars persist thru subsequent macro calls to daughter macros, and are finally lost when the original macro completes.

But what happens when a macro (recursion) calls itself?

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 23 2009 at 08:37 | IP Logged Quote BeachBum

If you’re talking about Insteon recovery, Jeff wrote one that is reentrant and reusable using very few Global Variables and is issued at the instance of a device change. Search for “generic SEND_INSTEON”. I have a different version that relies on global variables for each device and executes after the devices have been changed.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: January 24 2009 at 07:26 | IP Logged Quote GadgetGuy

Pete - Mucho thanks for the code pointer.

In looking it over I had a moment of great epiphany.

I don't know why I was making it so hard. After incrementing my retry loop I then inserted a Wait and then called the same macro (ie, recursion). This meant I could not use a LOCAL or TEMP as they would not persist.

But DUH! It just didn't dawn on me to merely Jump back to the Start of the program after my Wait, thus staying within the macro and allowing me to use a LOCAL var for the loop counter. Your referenced example turned the light on for me.

It also showed me a new way to handle LOCAL vars thru the SET SYSTEM command. I was not aware of that choice and it makes the code a lot easier to read.

So kudos and thanks all around for a very helpful post.


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum