Ticker Lua coding help

Latius

Hybrid Kart Mapper/Porter
I'm trying to make a ticker which would appear in the top right of the player's screen, and... Well, it's currently a bit jittery so far. In that while most of the time it smoothly scrolls from right to left as intended, sometimes it goes faster, slower or even reverses for a frame or two.

This is the current code I'm using:

Code:
local function drawCroppedTicker(v, text, viewarea)
	local frame = leveltime
	local length = string.len(text)
	local stringlen = 0
	
	for a = 1, length do
		local character = string.sub(text, a, a)
		if character == " " or character == "!" or character == ","
		or character == "." or character == "\"" then stringlen = $ + 4 
		elseif character == ":" or character == ";" or character == "`" then stringlen = $ + 5
		elseif character == "|" then stringlen = $ + 3
		else stringlen = $ + 8 end
	end
	
	frame = $ % stringlen
	
	local croppedString = text .. text
	local stringplace = 0
	local stringstart = 0
	local switch = false
	local newlen = 1
	for a = 1, length do
		local character = string.sub(croppedString, a, a)
		if character == " " or character == "!" or character == ","
		or character == "." or character == "\"" then stringplace = $ + 4 
		elseif character == ":" or character == ";" or character == "`" then stringplace = $ + 5
		elseif character == "|" then stringplace = $ + 3
		else stringplace = $ + 8 end
		if (not switch) and stringplace < frame then
			croppedString = string.sub(croppedString, 2, string.len(croppedString))
			stringstart = stringplace
		elseif not switch then 
			switch = true
			stringstart = frame - $
		else
			newlen = $ + 1
			if stringplace > frame + viewarea + 20 then
				croppedString = string.sub(croppedString, 1, newlen)
				break
			end
		end
	end
	
	
	v.drawString(308 - viewarea - stringstart, 2, croppedString, V_SNAPTOTOP)
	v.drawFill(300 - viewarea, 0, 10, 12, 233)
	v.drawFill(310, 0, 10, 12, 233)
end

Can someone help me out with finding where I've gone wrong, and how to fix it? I use the following call in the hud.add function:

Code:
drawCroppedTicker(v, "Police Assault in Progress  -  ", 102)
 
Using the V_MONOSPACE flag in v.drawString will render each letter with the same amount of spacing in between. This will make it so that removing letters from your string removes a consistent number of pixels each time.
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top