SaveFile(content, extension)Toy Basic does not provide direct access to file system for security reasons, though it allows you to save and open files with user interaction using system File Open and File Save dialogs. You can use function SaveFile to save a string content to a file fith desired extension. You will not know the actual file name, it will be provided by user. It will return non zero value in case of success and zero in case of a failure or if dialog is cancelled by user. In the example below you can see a small graphic editor with possibility to save and open images as PNG files
function OnMouseUp(x, y)
DrawCircle(x, y, 5)
end function
function OnKeyboard(c)
if c="s"
SaveFile(Screenshot(0, 0, GetWidth(), GetHeight()), "png")
elseif c="o"
img = OpenFile("png")
if not IsNull(img)
ClearScreen()
DrawImage(0, 0, img)
end if
elseif c="c"
ClearScreen()
end if
end function
See also: