It is currently March 29th, 2024, 12:35 am

[Solved] Problem with Alternative to Dynamic Variables

Discuss the use of Lua in Script measures.
User avatar
Mordasius
Posts: 1167
Joined: January 22nd, 2011, 4:23 pm
Location: GMT +8

[Solved] Problem with Alternative to Dynamic Variables

Post by Mordasius »

I was far from content with the solution proposed for Hexagon's problem with Substitute returned string before downloading image because of the error messages being returned by the calc Measure. I therefore played around with a LUA Script which I had hoped would write the correct URL to the variable #ImageToGet# which would then allow [MeasureImageDownload] to download the correct image to display.

The problem is that the stuff I have in function Update() seems to refresh the skin even though the [Variable] #ImageToGet# has not been changed. Help Please.
[/code]Substitute.lua

Code: Select all

PROPERTIES =
{
}
function Initialize()
   msImageLink = SKIN:GetMeasure('MeasureImageLink')
   sImageVar = SKIN:GetVariable('ImageToGet')
   sSubstitute = SKIN:GetVariable('SubstituteImage')
   sCheckString = SKIN:GetVariable('CheckString')
end

function Update()
    sImageLink = msImageLink:GetStringValue()
	if (sImageLink ~= sImageVar) and (sImageLink ~= sSubstitute)then
		if sImageLink == sCheckString then
			SKIN:Bang('!WriteKeyValue "Variables" "ImageToGet" "'..sSubstitute..'"')
		else
			SKIN:Bang('!WriteKeyValue "Variables" "ImageToGet" "'..sImageLink..'"')
		end	
	        SKIN:Bang("!Refresh")		
	end
   SKIN:Bang("!DisableMeasure MeasureLuaScript")
   SKIN:Bang("!EnableMeasure MeasureImageDownload")
   return "Image File Set" 
end -- Update
Update: Problem solved by smurfier over at http://rainmeter.net/forum/viewtopic.php?t=11246&p=64342#p64342