CDC Community

🔹 Historical Conservation 🔹

User Tools

Site Tools


The Conditional -write- Command (-writec-)

A very common situation is that of needing to write one of several possible messages on the screen. For example, you might like to pick one of five congratulatory messages to write after receiving a correct response from the student:

unit congrat randu N,5 $$ let TUTOR pick an integer from 1 to 5 at 1215 do N-2,ok1,ok2,ok3,ok4,ok5 * unit ok1 write Good! * unit ok2 write Excellent! * unit ok3 write I'm proud of you. * unit ok4 write Hurray! * unit ok5 write Great!

The -randu- command, “random on a uniform distribution,” tells TUTOR to pick an integer between 1 and 5 and put it in N. We then use this value of N to do one of five units to write one of five messages. There is a much more compact way of writing this:

unit congrat randu N,5 at 1215 writec N-2,Good!,Excellent!, I'm proud of you., Hurray!,Great!,

The -writec- command is similar to that of a conditional branching command, but the listed elements are pieces of text rather than unit names. Because -write- can be used to display any kind of text (including commas), it is necessary to use a different command name (-writec-) to indicate the conditional form of -write-, whereas in branching statements the commas separating the unit names are enough to tell TUTOR that it is a conditional rather than an unconditional form. (In conversation, “writec” is pronounced “write-see.”)

You can write whole paragraphs with nice left margins, just as with the -write- command:

writec N,,,Good!,Excellent!, I'm proud of you and so is your mother., Hurray!,Great!,

The elements of text are set off by commas. If N is 3, the student will see a three-line paragraph, since there are no commas at the end of “of” and “so”. If N is -1 or 0, no text will be displayed, since there is no text between the first few commas. Note that “x” is not the fall-through that it is for a unit name in a conditional branching command. Here, “x” is a legitimate piece of text which can be displayed, so the “„” form is the “fall-through”.

If you want commas to appear in some of your text elements, you have a problem, since the commas delimit elements. Consider this:

writec N,Hello!,How are you, Bill?,Hi there!,

If N is zero, we will see “How are you”, not “How are you, Bill?” The solution is to use a special character (↕):

writec N↕Hello!↕How are you, Bill?↕Hi there!↕

Now, if N=0 we will see “How are you, Bill?” While this special character (↕) is required if text elements contain commas, you may prefer to use it always, even when there are no commas. This special character is often called “the writec delimiter”.

The same kinds of embedding of other commands which are permitted by -write- are also permitted with -writec-:

writec 2c=b,I have ⊀s,ap⊁ apples., I will buy ⊀s,peachy⊁ peaches.,

The -writec- is affected by -size- and -rotate- commands, just like -write-.

The Conditional -calc- Commands: -calcc- and -calcs-

tutor/conditional_write_command.txt · Last modified: 2022/08/25 20:35 by