It is currently March 29th, 2024, 7:16 am

Problem with bang in Lua

Discuss the use of Lua in Script measures.
mattagiii
Posts: 2
Joined: April 13th, 2013, 6:04 am

Problem with bang in Lua

Post by mattagiii »

Hi all,

I have a (probably simple) issue with the Lua script I'm writing for my skin. All it is right now is a black square .png image that I'm attempting to change the tint of. So I wrote this:

Code: Select all

[Rainmeter]
Update=10

[Metadata]
Description=Fading Box

[Variables]
Alpha = 255

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#box.lua"
MeterToSetValue=meterBox

[meterBox]
Meter=IMAGE
ImageName=box.png
X=0
Y=0
ImageTint=255,255,255,#Alpha#
DynamicVariables=1
and without the Lua stuff the box displays just fine. However when I use this script:

Code: Select all

function Initialize()

   sMeterToSetValue = SELF:GetOption('MeterToSetValue')
   
   mtMeterToSetValue = SKIN:GetMeter(sMeterToSetValue)
   
   SKIN:GetVariable('Alpha')

end

function Update()
  
   iCurrentAlpha = tonumber(SKIN:GetVariable("Alpha"))
   
   if iCurrentAlpha > 1 then
   iNewAlpha = iCurrentAlpha - 1
   
   else
   iNewAlpha = iCurrentAlpha
   
   end

   SKIN:Bang('!SetVariable Alpha iNewAlpha')
   
   return(iNewAlpha)
   
end
it runs through with no problems, except after the first time through, my Alpha changes to nil. From there it obviously can't fade the box anymore. Seems like my setVariable bang might be wrong from the log, or maybe I'm just forgetting something in my .ini . It's probably something simple I'm missing but I literally just started Lua today and I can't figure it out. It'd be great if someone could help me out, and thanks in advance.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Problem with bang in Lua

Post by jsmorley »

The problem is that you are sending the string literal "iNewAlpha" in the bang by enclosing it in the string you are sending:

SKIN:Bang('!SetVariable Alpha iNewAlpha')

What you need to do is send the value of the variable iNewAlpha in the bang:

SKIN:Bang('!SetVariable Alpha '.. iNewAlpha)

The ".." syntax means "concatenate".


P.S. There is an alternative and preferred method for formatting a bang in Lua, that both eliminates forgetting about this, and makes it simpler:

SKIN:Bang('!SetVariable', 'Alpha', iNewAlpha)

You can and should send the arguments of the bang in separate values, separated by commas.

http://docs.rainmeter.net/manual/lua-scripting#Bang
mattagiii
Posts: 2
Joined: April 13th, 2013, 6:04 am

Re: Problem with bang in Lua

Post by mattagiii »

Ah, that's it! I was following some older example code and got it confused. I will definitely go to the manual to make sure my syntax is right next time. Thanks!!! Now to make skins do neat things...