You are on page 1of 1

--Defining some variables

-- The position from where the text should be blitted


positionx=240
red=Color.new(255,0,0)
--The text that has to be scrolled
text = "hello world from Lua"
--The speed at which the text should be scrolled
scrollspeed=4
while true do
--Clear the screen at the start of the loop
screen:clear()
--Check for controls
pad = Controls.read()
--Here is the main code which is used to scroll the text
--What it does is that using a for loop we define a variable i
--which runs from 1 to the number of characters in the variable "text"
for i=1, #text do
--next another variable is defined c and using string.sub we extract one charact
er from text and store it in c
local c = string.sub(text,i, i)
--Now we print this one the screen
screen:print(positionx+i*10, 126, c, red)
end
--What this code does is check that if the text has reached to the left end of t
he screen or not,
--If not then it subtracts scrollspeed from scrollx
--If it has reached the end then scrollx becomes 480 so that it scrolls from the
beginning
if positionx>(-#text*11) then
positionx=positionx-scrollspeed
else
positionx=480
end
screen.flip()
screen.waitVblankStart()
end

You might also like