How to dealy send commands so they occur one after another

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
CuriousOne
Posts: 14
Joined: Sun Dec 30, 2018 11:16 pm

How to dealy send commands so they occur one after another

Post by CuriousOne » Mon Dec 31, 2018 1:54 am

Hi Everyone,
I am just getting started with Livecode and I was wondering if someone could provide some insight on an problem I am having.

I am attempting to make a webpage slideshow that utilizes a single Browser instance.
The send commands are being set on top of each other, I am not sure how to delay the send commands so they occur one after another.

Currently the first card contains a single button named "Start"
That button has the following script.

Code: Select all

on mouseUp pButtonNumber
   go to card "Web"
end mouseUp
The second card has a single Browser widget item.
The second card has the following script.

Code: Select all

local x

on openCard
   repeat until x = 1
      send LoadUrl1 to this card in 10 seconds put URL1 into msg
      send LoadUrl2 to this card in 10 seconds put URL2 into msg
      if escapeKey is down then exit repeat
   end repeat
end openCard

on escapeKey

   put 1 into x
   put esc into msg
   go to card "start"
end escapeKey



command LoadUrl1
   set the url of widget "Browser" to "website-1"
end LoadUrl1


command LoadUrl2
   set the url of widget "Browser" to "website-2"
end LoadUrl2
The final plan is to have an Option menu on the start screen with options 1,2,3 for the user to pick how many sites they would like to rotate through.
Once they make a choice, fields would display on the start page which would allow them to type in the urls.
Once the user hits the Start button they would go to the "Web" card and the goal is to have the Browser Widget rotate through the urls.


Thank you

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: How to dealy send commands so they occur one after another

Post by MaxV » Mon Dec 31, 2018 4:55 am

use browserDocumentLoadComplete message, see http://livecode.wikia.com/wiki/Browser_widget
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

CuriousOne
Posts: 14
Joined: Sun Dec 30, 2018 11:16 pm

Re: How to dealy send commands so they occur one after another

Post by CuriousOne » Mon Dec 31, 2018 6:36 pm

I am not sure what to do with the browserDocumentLoadComplete message.
I thought maybe using it in an if statement like so, but I am not having any luck.
Is there a way to compare a parameter vs the actual website?

Code: Select all

local x
local Web1
local Web2

on openCard
   put "website1 url goes here" into Web1
   put "website2 url goes here" into Web2
   
   repeat until x = 1
      send LoadUrl1 to this card in 10 seconds put URL1 into msg
      // I am not sure if this is right
      if browserDocumentLoadComplete, Web1
      then
         send LoadUrl2 to this card in 10 seconds put URL2 into msg
         if escapeKey is down then exit repeat
         
      end if
   end if
end repeat
end openCard

on escapeKey
   put 1 into x
   put esc into msg
   go to card "start"
end escapeKey

command LoadUrl1
   set the url of widget "Browser" to "Web1"
end LoadUrl1

command LoadUrl2
   set the url of widget "Browser" to "Web2"
end LoadUrl2

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to dealy send commands so they occur one after another

Post by Klaus » Mon Dec 31, 2018 7:42 pm

Hi CuriousOne,

welcome to the forum!
You script will probably not work at all, check my comments:

Code: Select all

local x
local Web1
local Web2

on openCard
   put "website1 url goes here" into Web1
   put "website2 url goes here" into Web2
   
   ## If you do not hit ESC IMMEDIATELY, this loop will stack up to hundred or thousands of 
   ## "loadUrl" commands and your machine may explode! :-D
   repeat until x = 1
      
      ## Two commands need TWO lines or to be separated by SEMICOLON ;
      send LoadUrl1 to this card in 10 seconds put URL1 into msg
      // I am not sure if this is right
      
      ## Please look up unknown terms in the dictionary, there are always some example of their usage!
      if browserDocumentLoadComplete, Web1  then
         send LoadUrl2 to this card in 10 seconds put URL2 into msg
         if escapeKey is down then 
         exit repeat
         
      end if
   end if
end repeat
end openCard

on escapeKey
   put 1 into x
   put esc into msg
   go to card "start"
end escapeKey

command LoadUrl1
   ## You are not providing the local variable, Instead you are using the STRING "Web1"
   set the url of widget "Browser" to "Web1"
end LoadUrl1

## Same here
command LoadUrl2
   set the url of widget "Browser" to "Web2"
end LoadUrl2
I think you need something like this, please see the logics behind it:

Code: Select all

local Web1, Web2

## Every SEND returns an ID for the message sent, yo we can mange them later, 
## like cancel if neccessary. Exactly what we need here!
local the_sent_message_id

## So you want to display the first webpage after 10 seconds
on openCard
   put "website1 url goes here" into Web1
   put "website2 url goes here" into Web2
   
   ## Put names of messages to send in QUOTES
   send "LoadUrl1" to me in 10 seconds 
   
   ## See above:
   put the result into the_sent_message_id
   
   ## Every string also in QUOTES
   put "URL1" into msg
end openCard

on escapeKey
   put "esc" into msg
   
   ## See above, now we can cancel the delivery of the message if neccessary
   cancel the_sent_message_id
   go to card "start"
end escapeKey

command LoadUrl1
   ## Use local variable
   set the url of widget "Browser" to Web1
   
   ## NOW you can send the command to display the next url in 10 secs
   send "loadUrl2" to me in 10 secs
   
   ## See above:
   put the result into the_sent_message_id
end LoadUrl1

## Same here
command LoadUrl2
   set the url of widget "Browser" to Web2
end LoadUrl2
Best

Klaus

CuriousOne
Posts: 14
Joined: Sun Dec 30, 2018 11:16 pm

Re: How to dealy send commands so they occur one after another

Post by CuriousOne » Thu Jan 03, 2019 4:58 pm

Hi Klaus,
This is a big help thank you very much!
I am starting to understand Livecode a bit better.
Are there any recommend resources outside of the Livecode lessons that people find useful?

Thank you

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to dealy send commands so they occur one after another

Post by Klaus » Thu Jan 03, 2019 5:24 pm

Hi CuriousOne,

you're welcome! :D
Please check this series of very helpful stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html

Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”