07.05.2015 Views

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

106 BRONZE <strong>Edition</strong> <strong>Guide</strong><br />

You’re now using two parameters in the SUB statement above. Sum_dice represents the<br />

sum of the rolls, and num_dice gives the number of dice rolled. The subroutine doesn’t<br />

change num_dice but it does change sum_dice.<br />

To use this new subroutine, you must also use two arguments in the CALL statement. For<br />

example:<br />

CALL Rolldice (dice, 2)<br />

The first argument, dice, is the main program’s name for the sum of dice rolls, and 2 is the<br />

number of dice to be thrown.<br />

———————————————————————————————————————<br />

x Arguments share values with their corresponding parameters when the<br />

subroutine runs.<br />

———————————————————————————————————————<br />

Dice and sum_dice temporarily become equivalent so that when <strong>True</strong> <strong>BASIC</strong> returns to the<br />

main program dice has the value of sum_dice. Similarly, num_dice has the value of 2 during<br />

this call to the subroutine.<br />

This subroutine illustrates two kinds of parameters:<br />

• Num_dice is an input parameter that is only for sending information into a subroutine.<br />

Since an input parameter returns nothing, you may use constants for the corresponding<br />

argument on CALL statements as in the example above.<br />

• Output parameters are variables whose values are changed by the subroutine. They<br />

send information out from the subroutine to the corresponding argument in the main part<br />

of the program. Sum_dice is an output parameter.<br />

• <strong>True</strong> <strong>BASIC</strong> does not distinguish between input and output parameters; it's only in the<br />

way you use them.<br />

Built-in Functions<br />

You’ve already seen several of <strong>True</strong> <strong>BASIC</strong>’s built-in functions: RND, INT, SQR, and<br />

LCASE$, for example. Appendix C lists most of <strong>True</strong> <strong>BASIC</strong>’s built-in functions.<br />

To use a built-in function, all you do is refer to the function by name (perhaps giving it some<br />

information such as the number whose square root you want). <strong>True</strong> <strong>BASIC</strong> then “returns”<br />

a value to the program (such as the square root of the number you used with the function.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!