Skip to content

Play waits

cl4cnam edited this page Dec 1, 2023 · 3 revisions

In the previous tutorial, we played sounds. Those are palpable actions. Now, we are going to do non-palpable actions: we are going to wait. You think they aren't actions. Well, say they're passive actions.

So, as in the previous tutorial, we are going to do these passive actions in parallel. We are going to wait in parallel.

Note

This tutorial presents not a useful program per se but it's useful to understand how to do many useful programs ;). Don't skip it.

Prepare your environment

Do as in Hello World tutorial except that you change the names: playWaits, playWaits.html, playWaits.fg.

Write the program

Write these lines into playWaits.fg:

parallel ||
	awaitHumanText()
||
	waitSeconds(15)

displayNewMessage('The End')

As in the previous tutorial, the program is made up of two parts:

parallel ||
	awaitHumanText()
||
	waitSeconds(15)

and

displayNewMessage('The End')

The first part finishes only when both branches (awaitHumanText() and waitSeconds(15)) are finished. That is, when:

  • the user has entered a text
  • and 15 seconds has elapsed since the program started

So when you load playWaits.html, here is the timeline (if the user has entered a text before 15 seconds):

timeline2B

And here is the timeline if the user finishes to enter her/his text after 15 seconds:

timeline2B_2