====== Programming Tutorial VI - Raindrops Keep Falling On My Bonce - Part 1 ======
You've got an outside area, be it sylvan woodland, grotty industrial estate, medieval courtyard, or something else. You've been into the master settings and set things up so that you get those nice background effects depending on the weather. Very nice. But you want something more. You want to have extra descriptions depending on the weather. Descriptions that you've written yourself. Here we will describe how to do that. We will start with a fairly crude example and then at the end talk briefly about how to make it more sophisticated.
First we'll have a little look at how the weather works. Hidden in the background of the Island is what's called a //Weather Status Number//. This is a number between one and seven. This number interacts with the game time clock to give forty nine different situations, as summarized with the following handy table that comes with the Weather Contrivance.
{{ http://improbableisland.com/external/wt/10-places-progtutvi-weathertable.jpg | Weather status numbers and what they mean. }}
How when and why the weather changes from one status number to another doesn't concern us here. All that matters is that the Weather Contraption is used to ask what value the Weather Status Number currently holds.
If we look at the weather table above, we notice that rain occurs when the Weather Status Number is five, six or seven. So what we want to set up is a program which asks: "Is the Weather Status 5,6 or 7?" and if the answer is "Yes" then show an extra page that you've decorated with your extra "It's raining!" description.
Well we can't quite use a Weather Contrivance like that. The way that the Contrivance works is that it has a parameter which you set to a __single__ number from one to seven, say five, and then you have a Contrivance which asks "Is the Weather Status Number currently equal to five?" Since we are looking for three different numbers (five, six and seven) we need three Weather Contraptions, one for each number we want to check. We take these, and setting the parameters on these to five, six or seven, we place them in the programming grid, together with a Show Page Contraption (with parameter set to show the page with our new "It's raining!" description) as follows.
Note: As we said in an earlier tutorial, which order you put the weather contrivances in is unimportant, the program works identically whichever way round they go.
{{ http://improbableisland.com/external/wt/11-places-progtutvi-weather-rain-showpage.jpg | It's raining! }}
C'est Voila! We have built our weather description program.
Suppose that you want to differentiate a little more. Two, three or even more extra page descriptions depending on the weather. Currently you can do this by having two, three or even more programs running in the room, one for each different page that might be displayed. There are ways round this, but they use tricks that have not yet been covered in the tutorials. See [[places:progtutvii|Tutorial VII]] for ideas about how to split the weather into two different groupings, each with their own page. See [[places:advtuti|Advanced Tutorial I]] and its following tutorial for tips as to how to split the weather into three or more different groupings.
Note for budding programmers
Here we have used multiple conditions. There are three Weather Contrivances in the first row, all asking questions about the weather. If ANY one of these Contrivances answer 'Yes' then the row passes, the program goes onto the next row, and raindrop graphics are produced.
Your program is run one line at a time. If any Contraptions are found, then their instructions are carried out, any Contrivances found, and the relevant question is asked. If there are any Yes answers, or if there is a Contraption, then the next line of the program is run, otherwise the program is terminated. The best way of thinking about Contraptions is to think of them as always giving an automatic Yes answer.
\\
The program logic can be summed up in the following diagram.
{{ http://improbableisland.com/images/places/faq/flowchart.png | Go with the flow! }}
Hang about a bit, what are those extra arrows going off to the right? And just what is that extra square there on the right hand side? That hasn't been covered in the tutorials yet! Well that's the //Escape Hatch//, and we'll deal with that in the next tutorial.
----
[[places:progtutVII|Go to next tutorial.]]\\
[[places:progtutV|Return to previous tutorial.]]\\
[[places:tutcontents|Tutorial Contents Page]]\\
[[places:progelements|Return to Introduction to Programming.]]\\
[[places:start|Return to Places Overview]]