A Timing Issue

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

A Timing Issue

Post by lohill » Wed Jul 31, 2013 6:54 pm

My program has the ability to open 3 different internal browsers concurrently. I keep a list of those browsers in a global variable called gBrowserList. Each line in the list contains the name of the browser stack and the browser ID comma delimited. I have a command called 'newBrowser' which when called from the File Menu will open, connect and update that list. I can call that menu manually and end up with gBrowserList looking like:
Browser1,5
Browser2,8
Browser3,22
With all browsers closed thee list looks like:
Browser1,0
Browser2,0
Browser3,0

If a browser is open and I do something that needs to access it, it does so without a problem. The issue comes when no browsers are open and I want to access one. Right now I have to go to the File Menu to take 'newBrowser' and then issue the command to do something with it. I would like to make it so that when no browsers are present, a command that requires the use of a browser will open it automatically and use it.

To that end I have written the following function:

function CheckForBrowser
global gBrowserList
put false into bFound
repeat with i=1 to number of lines of gBrowserList
put line i of gBrowserList into tLine
if item 2 of tLine > 0 then
put true into bFound
exit repeat
end if
end repeat
if bFound is false then
newBrowser
repeat
put item 2 of line 1 of gBrowserList into tID
if tID > 0 then
put true into bFound
exit repeat
else
wait 2 ticks
end if
end repeat
end if
return bFound
end CheckForBrowser

With no break points set the function just hangs. Command-Period stops it at the command 'wait 2 ticks'. If I put a break point at the command 'wait 2 ticks' and execute the function it stops at that point and when I tell it to continue everything works just fine.

Any suggestions on how I might make this work?

Thanks,
Larry

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: A Timing Issue

Post by shaosean » Thu Aug 01, 2013 7:07 am

Look up browserNewInstance and revBrowserInstances

It looks like your script might be getting caught in that last repeat loop if "item 2 of line 1" never changes from 0.. Also, it looks like your function will always return TRUE, so no real reason to have it as a function that returns..

Code: Select all

on mouseUp
   if (revBrowserInstances() = EMPTY) then
      newBrowser
   end if
end mouseUp

on newBrowser
   if (revBrowserOpen(the windowID of this stack) = EMPTY) then
      # error
   end if
end newBrowser

on browserNewInstance pBrowserID
   # do what you need to do here as you are guaranteed to have the web browser object
end browserNewInstance

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: A Timing Issue

Post by lohill » Fri Aug 02, 2013 10:07 pm

Shaosean,

Thank you very much for calling to my attention 'browserNewInstance'.

Best,
Larry

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: A Timing Issue

Post by shaosean » Sat Aug 03, 2013 6:02 am

No problem..


Fear of spiders is aracnaphobia, fear of tight spaces is claustrophobia, fear of Chuck Norris is called Logic

Post Reply