Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Order of Execution Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: March 18 2007 at 08:50 | IP Logged Quote TonyNo

This one has been driving me nuts for a while.

This bit of code does not happen in the order I would expect...

Code:
ph_setvar_s( 1, 1, "Table lamp on") + ph_setvar_s( 1, 3, "{WINAMP STATUS}") + if( ph_getvar_s( 1, 3) = "Playing", ph_macro("PLAY PAUSE") + ph_delay(1000), 0) + ph_playsound( "ding.wav", 0) + ph_tts( ph_getvar_s( 1, 1)) + ph_ttswait( -1) + if( ph_getvar_s( 1, 3) = "Playing", ph_macro("PLAY PAUSE"), 0) + ph_macro("TABLE LAMP ON")


It should check to see if Winamp is playing, and, if so, pause it, play the WAV, do the TTS, resume Winamp playing if necessary, then fire the macro.

What actually happens is everything THEN a brief pause/play of Winamp when playing!

Maybe I can't rely on calling a macro when order of execution is important?
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 19 2007 at 17:56 | IP Logged Quote dhoward

Tony,

Looking at the above code, everything should be fine. The only potential problem is if your macros have any "Wait" statements. Everything should happen in order as you expect. When you call a macro, execution will continue until the first "Wait" statment. At that time, the macro state is stored and control is returned to whatever called the macro. When the macro wait is expired, the macro is added back to the execution queue which will not be serviced until the currently running operation is completed (the formula above in this case).

Does this sound like your problem?

In addition to the "Wait" command, a macro messagebox or input box will provide similar behavior.

Unfortunately, there is no easy way around this without putting your formula above into a macro. You would then be able to code around it. You could do it like this:

Code:

Formula Immediate ph_setvar_s( 1, 1, "Table lamp on") + ph_setvar_s( 1, 3, "{WINAMP STATUS}")
Jump if( ph_getvar_s(1,3) = "Playing",1,3)
SubMacro "PLAY PAUSE"
Wait 1
Formula Immediate ph_playsound( "ding.wav", 0) + ph_tts( ph_getvar_s( 1, 1)) + ph_ttswait( -1)
Jump if( ph_getvar_s(1,3) = "Playing",1,2)
SubMacro "PLAY PAUSE"
SubMacro "TABLE LAMP ON")


The key Im illustrating here is the "SubMacro" command. This command was created for exactly the type of situation that you're having. When a macro is called with the SubMacro command, control is NOT returned to the calling macro until the submacro actually completes. Even if the submacro waits or pops up a messagebox, the calling macro execution will be halted until the submacro is complete. At the same time, other execution events are allowed to process without hanging the execution queue.

Hope this helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: March 19 2007 at 18:20 | IP Logged Quote TonyNo

SubMacro?! When did that show up?

Here is what I ended up with that works as I believe it should...

Code:
ph_setvar_s( 1, 1, "Table lamp on") + ph_setvar_s( 1, 3, ph_winampinfo ( "status", 0, 0 )) + if( ph_getvar_s(1, 3) = "playing", ph_winampctrl( "pause", 0, "" ) + ph_delay(1000), 0) + ph_playsound( "ding.wav", 0) + ph_tts( ph_getvar_s( 1, 1)) + ph_ttswait( -1) + ph_macro("TABLE LAMP ON") + if( ph_getvar_s( 1, 3) ="playing", ph_winampctrl("play", 0, "" ), 0)
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 

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