Welcome to the Rockbox Technical Forums!
local print = require "print" -- print.lua is in the /rockbox/rocks/viewers/lua directorymath.randomseed(os.time()) -- seeds the random number generatorprint.clear()print.f("%d %d %d %d", math.random(1,6), math.random(1,10), math.random(1,10), math.random(1,100))rb.sleep(rb.HZ * 5) --waits 5 seconds
local print = require "print" -- print.lua is in the /rockbox/rocks/viewers/lua directorylocal r = math.randomlocal items = { "sword", "shield", "potion"}math.randomseed(os.time()) -- seeds the random number generatorprint.clear()print.f("%s", items[r(1, #items)])rb.sleep(rb.HZ * 5) --waits 5 seconds
require "buttons"local print = require "print" -- print.lua is in the /rockbox/rocks/viewers/lua directorylocal line = 1, max_line, w, hlocal button = 0local btn = rb.buttonslocal r = math.randomlocal items = { "sword", "shield", "potion"}math.randomseed(os.time()) -- seeds the random number generatorprint.clear()repeat if button >= 0 and bit.band(button, btn.BUTTON_REL) == 0 then -- make sure to skip sys_events ( < 0 ) and button release if line == max_line then print.clear() line = 1 end line, max_line, w, h = print.f("%d. %s", line, items[r(1, #items)]) end button = rb.button_get(true) -- true = block till presseduntil(button == btn.BUTTON_BACK)
require "actions"local print = require "print" -- print.lua is in the /rockbox/rocks/viewers/lua directorylocal line = 1, max_line, w, hlocal act = rb.actionslocal action = act.NONElocal r = math.randomlocal TIMEOUT_BLOCK = -1local TIMEOUT_NOBLOCK = 0local left_margin = rb.font_getstringsize("W ", font or rb.FONT_UI)local items = { "sword", "shield", "potion", "really long text item that needs to word wrap to another line", "really really long text item that needs to word wrap to another line and then to additional lines after that"}math.randomseed(os.time()) -- seeds the random number generatorprint.opt.overflow("none")print.settings = print.opt.get()print.clear()local function word_wrap(item, max_width) local item_disp="" local chars = 1 repeat --remove what has alread been displayed item_disp = string.sub(item, 1, chars) chars = chars + 1 until(rb.font_getstringsize(item_disp, font or rb.FONT_UI) >= max_width - left_margin) local fsp = string.find(item, "%s", chars - 3) or 0x0 --rb.splash(100, chars .. " " .. fsp) if fsp ~= 0 and fsp < chars then chars = fsp + 1 end item = string.sub(item, chars) line, max_line, w, h = print.f("%s", item) if w > max_width then return word_wrap(item, max_width) -- function tailcall endendrepeat if action == act.PLA_SELECT or action == act.NONE then if line == max_line then print.clear() line = 1 end local item = items[r(1, #items)] line, max_line, w, h = print.f("%s", item) if w > print.settings.width then word_wrap(item, print.settings.width) end end action = rb.get_plugin_action(TIMEOUT_BLOCK) -- block till presseduntil(action == act.PLA_EXIT or action == act.PLA_CANCEL)
Page created in 0.176 seconds with 21 queries.