Function LoadNumericValue

LoadNumericValue(name, value)
Toy Basic does not provide direct access to file system for security reasons, though it allows you to save and load some program settings, like high scores, user names etc. Settings are remembered remembered per EXE file and per program name. If you rename or move your EXE file or rename the program, settings will be lost. Function LoadNumericValue should be used to load a previously saved numeric setting. If the setting was not saved before, it will return the value supplied in second parameter:
program "Closest Distance Demo" ' settings will be lost if you change program name

$closestDistance = LoadStringValue("closest distance", -1)

function DrawClosestDistance()
	ClearScreen()
	DrawText(10, 10, "Click as close to the window center as possible")
	if $closestDistance > 0
		DrawText(10, 30, "Closest so far is: " & $closestDistance)
	end if
end function

function OnMouseUp(x, y)
	distance = sqrt( (GetWidth() / 2 - x)^2 + (GetHeight() / 2 - y)^2 )
	if $closestDistance < 0 or distance < $closestDistance
		$closestDistance = distance
		SaveStringValue("closest distance", $closestDistance)
		DrawClosestDistance()
	end if
end function

DrawClosestDistance()

See also: