It is currently April 24th, 2024, 11:19 pm

Long Bangs and double quote problem

Discuss the use of Lua in Script measures.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Long Bangs and double quote problem

Post by AlC »

Hey Guys,

I done a simple Lua script for me and now I want to use some bangs in it. The normal bangs aren't the problem, but I have 2+... bangs that don't work and I have no idea why.
The problem is that the meters aren't in the same config like the lua script + I have a lua variable New in my bangs.

Here are the 2 bangs
Meter=Music Option=LeftMouseUpAction Value=[...] Config=AlcBar\Bar

SKIN:Bang("!SetOption Music LeftMouseUpAction [!SetOption BgLineLightTop H (#Y_BgMusic#-1)][!SetOption BgLineDarkTop H (#Y_BgMusic#-2)][!SetVariable H_LineTop #Y_BgMusic#][!SetVariable H_LineBottom (#H_Bar#-#Y_BgMusic#-"..New..")][!HideGroup AlcTab][!Show AlcBar\Music][!HideMeterGroup Hover][!ShowMeter Music_Active][!Update] AlcBar\Bar")

Error: Bang: Config "AlcBarBar" not found
Meter=BgLineLightBottom Option=H Value=(#H_Bar#-#Y_BgMusic#-"..New.."-1) Config=AlcBar\Bar

SKIN:Bang("!SetOption BgLineLightBottom H (#H_Bar#-#Y_BgMusic#-"..New.."-1) AlcBar\Bar")

Error: Bang: Config "BgLineLightTop" not found
Hope someone can help me
Rainmeter - You are only limited by your imagination and creativity.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Long Bangs and double quote problem

Post by smurfier »

In Lua, forward slashes are an escape character. This means that if you want to use a literal forward slash in your string you need to double it. Also, you forgot some quotes. When you need to use quotes inside the string, use ' to define it.

Code: Select all

SKIN:Bang('!SetOption Music LeftMouseUpAction """[!SetOption BgLineLightTop H (#Y_BgMusic#-1)][!SetOption BgLineDarkTop H (#Y_BgMusic#-2)][!SetVariable H_LineTop #Y_BgMusic#][!SetVariable H_LineBottom (#H_Bar#-#Y_BgMusic#-'..New..')][!HideGroup AlcTab][!Show AlcBar\Music][!HideMeterGroup Hover][!ShowMeter Music_Active][!Update]""" AlcBar\\Bar')
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
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: Long Bangs and double quote problem

Post by AlC »

smurfier wrote:In Lua, forward slashes are an escape character. This means that if you want to use a literal forward slash in your string you need to double it. Also, you forgot some quotes. When you need to use quotes inside the string, use ' to define it.
Ahh doubled. Thanks smurfier, I will try it tomorrow and let you know if it works.

Good Night
Rainmeter - You are only limited by your imagination and creativity.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: Long Bangs and double quote problem

Post by AlC »

Now that I found that Lua supports dynamic variables (in contrast to RM), I need the 2 bangs at the moment not. And my other bangs work now, too. Like:

SKIN:Bang('!SetVariable H_LineBottom (#H_Bar#-#Y_Bg'..Tab..'#-#H_'..Tab..'#)')
SKIN:Bang("!AddBlur 1,#X_LineLight#,(#Y_BgMusic#-1),(#X_LineLight#+#W_Music#+1),(#Y_BgMusic#+"..New.."+1)")

Now I want to know when I should use " and ' in Lua and Bangs. And what is the difference between the two.
Rainmeter - You are only limited by your imagination and creativity.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Long Bangs and double quote problem

Post by jsmorley »

There really is no difference as far as Lua is concerned between a single and double quote. Lua, like most languages, uses both primarily to allow quoting within quoting by alternating them.

Having said that, what I find makes things the easiest to read and debug when using Lua with Rainmeter, is to always use single quotes to quote strings in Lua itself, and use double quotes when you want to send a quoted string to Rainmeter. That way it is easy to spot when you are sending quotes to Rainmeter, when it needs it, like when there is white space in a bang value, and when you are just quoting a string in Lua.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: Long Bangs and double quote problem

Post by AlC »

Okey like this for example:

SKIN:Bang('!SetOption Meter Text "A '..color..' Text" ')
Rainmeter - You are only limited by your imagination and creativity.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Long Bangs and double quote problem

Post by jsmorley »

AlC wrote:Okey like this for example:

SKIN:Bang('!SetOption Meter Text "A '..color..' Text" ')
Correct.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: Long Bangs and double quote problem

Post by AlC »

Okay thank you. This was probably not the last question on Lua :)
Rainmeter - You are only limited by your imagination and creativity.