It is currently September 23rd, 2020, 4:54 pm

[Script] Lua Marquee

Discuss the use of Lua in Script measures.
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Script] Lua Marquee

Post by smurfier »

XANCI wrote:Come up with a simple way, and can use any font:
1.Set W&H in your STRING meter
2.lua code

Code: Select all

function Initialize()
	sText=string.rep(' ',N)..tostring(SKIN:GetVariable("Text"))
	iTextLength=string.len(sText)
	iStart=iTextLength-1
end

function Update()
	iStart=iStart%iTextLength+1
	return string.sub(sText,iStart,iTextLength)
end
the "N" in string.rep represents how many spaces are needed to fill the STRING meter with the given W, you can find it manually and then replace N
You can use any font with my script. It's just recommended to use a monospaced font so that it will always be the same width. My script also takes into consideration strings that are smaller than the width and strings that change.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
XANCI
Posts: 106
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

Re: [Script] Lua Marquee

Post by XANCI »

smurfier wrote: You can use any font with my script. It's just recommended to use a monospaced font so that it will always be the same width. My script also takes into consideration strings that are smaller than the width and strings that change.
Well I just demonstrated an alternative to make a marquee, it's easy to add functions such as whether to scroll if the string's length is shorter than the width or proper response to string's change.

Infact, most skins with other Fonts bond STRING meter's width in pixels not characters, so I think this is a more conventional way.

Another problem is that if the string consist of dual-byte characters in some languages, the display will be error when you cut through one of them. Any hints?
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Script] Lua Marquee

Post by smurfier »

I really don't understand what you're saying. Both of our scripts do the same thing, only mine does more. Neither of them do things in pixels.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
XANCI
Posts: 106
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

Re: [Script] Lua Marquee

Post by XANCI »

smurfier wrote:I really don't understand what you're saying. Both of our scripts do the same thing, only mine does more. Neither of them do things in pixels.
I don't want to bother separate codes form my completed skin so I will just post the download link here
http://xanci.deviantart.com/#/d4ar0ll

This is the mediaplayer section
20120309000312.jpg
The title/artist/album display's width is 192 pixels, and the texts which contain strings longer than 192 pixels in ANY FONT will scroll if mouse is on them.
You could find out how it difference the string's length and response to changes, and then judge who does more

Still, if there are dual-byte characters such as Chinese and Japanese, the text will be a mess. Once string.sub() starts from the middle of a dual-byte character, all characters behind will out of place. Any idea?
You do not have the required permissions to view the files attached to this post.
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Script] Lua Marquee

Post by smurfier »

You would need a setting on the measure that tells the script that it's a dual-byte string and act accordingly.

The hard part is spaces. They aren't dual-byte.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
XANCI
Posts: 106
Joined: September 18th, 2011, 6:37 am
Location: Nanjing, China

Re: [Script] Lua Marquee

Post by XANCI »

Note that all dual-byte characters' value is larger than 127, so the code here can find acutual position for each character and total number of characters

Code: Select all

	sMD[i]=string.rep(' ',63)..sMT[i]
	iML[i]=string.len(sMD[i])
	j=1
	k=1
	while j<=iML[i] do
		iB[i][k]=j
		k=k+1
		if string.byte(string.sub(sMD[i],j,j))<128 then
			j=j+1
		else
			j=j+2
		end
	end
	iCL[i]=k-1
and when scrolling text, use the indicator for characters

Code: Select all

	iS[i]=iS[i]%iCL[i]+1
	SKIN:Bang("!SetOption Meter"..sM[i].." Text \"\"\""..string.sub(sMD[i],iB[i][iS[i]],iML[i]).."\"\"\"")
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Script] Lua Marquee

Post by smurfier »

Updated to use current Rainmeter standards and to add the options Pause and Position.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Skymil
Posts: 24
Joined: July 19th, 2011, 9:44 am
Location: France

Re: [Script] Lua Marquee

Post by Skymil »

Hello. Thank you for your script. There is a little issue when Position=LEFT is used. When the text reappears, the characters are not at the right position (too much to the left) and the string moves little by little to the right (I don't know if it is clear enough).
Also, a little error in your first post: MouseLeaveAction=!CommandMeasure Lua [color=#FF0000]"[/color]Pause,Timer=0,0[color=#FF0000]"[/color]
User avatar
smurfier
Moderator
Posts: 1937
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: [Script] Lua Marquee

Post by smurfier »

Skymil wrote:Hello. Thank you for your script. There is a little issue when Position=LEFT is used. When the text reappears, the characters are not at the right position (too much to the left) and the string moves little by little to the right (I don't know if it is clear enough).
Also, a little error in your first post: MouseLeaveAction=!CommandMeasure Lua [color=#FF0000]"[/color]Pause,Timer=0,0[color=#FF0000]"[/color]
What you are experiencing is the fact that without using a Monospace font, each character has a different width.

I am having no issue with omitting the quotes around the command.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Skymil
Posts: 24
Joined: July 19th, 2011, 9:44 am
Location: France

Re: [Script] Lua Marquee

Post by Skymil »

I see thank you. Hmm, you are right. Maybe I added a space without care. Sorry.