USE

Some of you programs may share common code. For example you may want to use identical functions in two different progarms. Of course you can copy/paste the code, but there is a better alternative in Toy Basic. To do this:

  1. Write all the common code in a common BAS file. For example "common.bas"
  2. In each program add keyword USE followed by a string value with common BAS file name

Here is an example below.

Common BAS file "common.bas":

$Pony = #"pony.png"
function DrawPony (x, y)
	DrawImage (x, y, $Pony)
end function

First program "program1.bas":
use "common.bas"
function OnMouseUp (x, y)
	DrawPony (x, y)
end function

Second program "program2.bas":
use "common.bas"
$nStartTime = GetTime ()
function OnTimer ()
	ClearScreen ()
	nTimePassed = GetTime () - $nStartTime
	x = nTimePassed / 100
	DrawPony (x, 10)
end function

You can aslo use asolute paths with keyword USE:

use "c:\My Documents\My Programs\common.bas"

See also: