Turtle Library for Lua - text(String, int, int, int) - change font and text size?

1.4k views Asked by At

Just a general question. Using text("Text", 0, 0, 0) how would I change the font and/or size of the text if at all possible? I was trying to make a timer - I've been using Lua for two or three years now to cheat through Math ("Is it okay if I use my iPod as a calculator for the test?" "Sure." "Thanks! smirk") and have just now started to explore its capabilities - by running a loop and printing text to the window every second but the text is just too damn small.

io.write("Enter the time in seconds that the timer will run: ")
local time = io.read('*number')

local function sleep(s)
   local clock = os.clock
   local t0 = clock()
   while clock() - t0 >= s do
   end
end

require('turtle')

function timer(time)
   local erase = snap()
   while time ~= 0 do
      text(time, 0, 0, 0)
      time = time - 1
      sleep(1)
      undo(erase)
   end
   text("Done", 0, 0, 0)
end

wait()
1

There are 1 answers

0
ryanpattison On BEST ANSWER

You can call the font function to set up a different font before calling text. Here are some example calls:

font("serif")  -- change font
font(32)  -- change size
font("italic")

font("serif 32") -- or change both

text("Text")

Or in your code example:

io.write("Enter the time in seconds that the timer will run: ")
local time = io.read('*number')

local function sleep(s)
   local clock = os.clock
   local t0 = clock()
   while clock() - t0 >= s do
   end
end

require('turtle')
font(64)

function timer(time)
   local erase = snap()
   while time > 0 do
      text(time)
      time = time - 1
      sleep(1)
      undo(erase)
   end
   text("Done")
end

wait()