It is currently March 28th, 2024, 5:47 pm

LUA data is nil

Get help with installing and using Rainmeter.
mworsnop
Posts: 16
Joined: December 14th, 2017, 1:20 am

LUA data is nil

Post by mworsnop »

I am calling a LUA and trying to see if the data is there and if so then it will display the icon. However when I print the variable weatherData its NULL (nil).

Guessing I am calling the wrong function or something?

I am trying to learn all of this so thanks for your patience and help!


The INI:

[WeatherForecast]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=600

Url=http://api.wunderground.com/api/#ApiKey#/alerts/pws/q/#Zip#.xml
RegExp=(?siU)<type>(.*)<.*<type>(.*)<.*(?(?=.*<description>).*<description>(.*)<.*)(?(?=.*<description>).*<description>(.*)<.*)(?(?=.*<description>).*<description>(.*)<.*)

ForceReload=1
FinishAction=[!EnableMeasureGroup Weather][!UpdateMeasure CheckAlerts][!UpdateMeter *][!Redraw]



LUA this is part of it:

function Initialize()

weatherParent = SKIN:GetMeasure('WeatherForecast')

end

function Update()


weatherData = weatherParent:GetStringValue()


print (weatherData)
....
end
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: LUA data is nil

Post by balala »

When you post such questions, it would be a good idea to also post the values of the needed variables. Not always works using any key.
However, instead of using the print function, you have two possibilities:
  • Replace the print (weatherData) line with the following command: SKIN:Bang('!SetVariable', 'MyVariable', weatherData). This command returns the appropriate string to the MyVariable variable, which can be used into the skin. Just don't forget to add a DynamicVariables=1 option to the meter or measure which uses it.
  • Replace the same print (weatherData) line with return weatherData. In this case the appropriate Script measure of your skin gets the returned value, so for example to can show it on the screen, you have to use the following String meter:

    Code: Select all

    [StringMeter]
    Meter=String
    MeasureName=LuaMeasure
    String=%1
    where obviously LuaMeasure is the name of the Script measure, existing in your code. Something like:

    Code: Select all

    [MeasureLuaScript]
    Measure=Script
    ScriptFile=#@#YourLuaScriptFile.lua
mworsnop
Posts: 16
Joined: December 14th, 2017, 1:20 am

Re: LUA data is nil

Post by mworsnop »

The LUA is looking for certain data and if its there will enable an icon to be visible.

The weatherData is a local var just used in the update function. Seems weird it doesn't show up with print

I will give this a try
mworsnop
Posts: 16
Joined: December 14th, 2017, 1:20 am

Re: LUA data is nil

Post by mworsnop »

I am trying to debug print the local var in the LUA. Its hard to tell whats happening inside the LUA. I dont need to return it just using it locally.


function Update()

weatherData = weatherParent:GetStringValue()

print (weatherData)

alertData = string.match(weatherData, '<feature>(.-)</feature>')


if alertData then ...
User avatar
khanhas
Posts: 40
Joined: October 26th, 2016, 5:00 pm

Re: LUA data is nil

Post by khanhas »

You didn't set StringIndex for [WeatherForcast], that's why it didn't return any string value for you to get in Lua.
mworsnop
Posts: 16
Joined: December 14th, 2017, 1:20 am

Re: LUA data is nil

Post by mworsnop »

Sorry I dont understand why I would set a stringindex in the opening call. It should be returning the entire XML string.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: LUA data is nil

Post by balala »

mworsnop wrote:Sorry I dont understand why I would set a stringindex in the opening call. It should be returning the entire XML string.
Right. But finally, what is the question here?
mworsnop wrote:I am trying to debug print the local var in the LUA. Its hard to tell whats happening inside the LUA. I dont need to return it just using it locally.


function Update()

weatherData = weatherParent:GetStringValue()

print (weatherData)

alertData = string.match(weatherData, '<feature>(.-)</feature>')


if alertData then ...
There you don't need the print function. Don't keep using it, in the codes used by the Rainmeter skins, it is not needed. The alertData is well defined even without the print function.

But again: to can help, we would need the whole code. Including the values of the variables. If you don't want to give them, then please find a not real, but functional value for that variable and post that one. It'd be much easier for anyone to help you if you'd help him to can help.
mworsnop
Posts: 16
Joined: December 14th, 2017, 1:20 am

Re: LUA data is nil

Post by mworsnop »

I am using the print for debugging so I can see what its looking at. Thats all.
I posted the guts of the code in my first post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: LUA data is nil

Post by balala »

:confused:
mworsnop wrote:I am using the print for debugging so I can see what its looking at. Thats all.
But where do you see it, using the print function in the code used by the Rainmeter skin? Am I missing something obvious?
mworsnop wrote:I posted the guts of the code in my first post.
I think I'd need the whole code and the whole lua code. But as you wish...
mworsnop
Posts: 16
Joined: December 14th, 2017, 1:20 am

Re: LUA data is nil

Post by mworsnop »

Here is the complete INI and LUA. I am just using the print to make sure the code it working thats all. This is the first time I have messed with this coding so stabbing in the dark

Code: Select all

;======================================================================================
; Rainmeter configuration file
; Updated Dec 17 2017
; 
; 
;======================================================================================

[Metadata]
Name=WX WU Alerts
Author=Mark Worsnop
Information=Displays alerts using Weather Underground 
License=Attribution-NonCommercial-ShareAlike 4.0 International
Version=0.9

; example
;  http://api.wunderground.com/api/xxxxxx1/alerts/pws/q/pws:KNVRENO45.xml
;
;<alerts>
;<alert>
;<type>WND</type>
;<description>High Wind Watch</description>
;<date>3:35 am PST on December 18, 2017</date>
;<date_epoch>1513596900</date_epoch>
;<expires>12:00 PM PST on December 20, 2017</expires>
;<expires_epoch>1513800000</expires_epoch>
;<message>
;...High wind watch in effect from Tuesday evening through Wednesday morning... The National Weather Service in Reno has issued a high wind watch, which is in 
;</message>

;======================================================================================

[Variables]
ApiKey=xxxxx
Zip = pws:KNVRENO45

TextFont=Fira Sans
MediumTextFont=Fira Sans Medium
ThinFont=Fira Sans Light
MonoFont=Fira Mono

LabelColor=220,220,220
ValueColor=245,249,255
BarBackColor=#LabelColor#,75
BackgroundAlpha=170
BackgroundColor=70,70,70,#BackgroundAlpha#
NetBarBackColor=60,60,60
ImagePath=#@#Images\




[Rainmeter]
Update=600
SkinWidth=500


[WeatherForecast]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=600

Url=http://api.wunderground.com/api/#ApiKey#/alerts/pws/q/#Zip#.xml
RegExp=(?siU)<type>(.*)<.*<type>(.*)<.*(?(?=.*<description>).*<description>(.*)<.*)(?(?=.*<description>).*<description>(.*)<.*)(?(?=.*<description>).*<description>(.*)<.*)

 ForceReload=1
 FinishAction=[!EnableMeasureGroup Weather][!UpdateMeasure CheckAlerts][!UpdateMeter *][!Redraw]

;
;======================================================================================
;Extract current weather & time information
;======================================================================================
[CheckAlerts]
Measure=Script
ScriptFile=#CURRENTPATH#CheckAlerts.lua
Group=Weather
UpdateDivider=-1
Disabled=0


[MeasureTime]
Measure=Time
Format="Updated %A at %I:%M %p"
UpdateDivider=-1

[GetDescription3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[WeatherForecast]
StringIndex=3
UpdateDivider=-1

[GetDescription4]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[WeatherForecast]
StringIndex=4
UpdateDivider=-1

[GetDescription5]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[WeatherForecast]
StringIndex=5
UpdateDivider=-1

;======================================================================================
;Display alerts
;======================================================================================

[DisplayDateTime]
MeasureName=MeasureTime
Meter=STRING
X=490
Y=275
FontColor=#FontColor#
StringStyle=NORMAL
FontSize=10
StringAlign=RIGHT
StringEffect=Shadow
FontFace=#Font#
Antialias=1

[DisplayDescription3]
MeasureName=GetDescription3
Meter=STRING
X=12
Y=20
FontColor=#FontColor#
FontSize=24
StringAlign=LEFT
StringStyle=NORMAL
StringEffect=Shadow
FontFace=#Font#
Antialias=1
Postfix=""

[DisplayDescription4]
MeasureName=GetDescription4
Meter=STRING
X=12
Y=60
FontColor=#FontColor#
FontSize=24
StringAlign=LEFT
StringStyle=NORMAL
StringEffect=Shadow
FontFace=#Font#
Antialias=1
Postfix=""


[DisplayDescription5]
MeasureName=GetDescription5
Meter=STRING
X=12
Y=100
FontColor=#FontColor#
FontSize=24
StringAlign=LEFT
StringStyle=NORMAL
StringEffect=Shadow
FontFace=#Font#
Antialias=1
Postfix=""

[MeterAlert]
Meter=Image
X=1
Y=1
ImagePath=#ImagePath#\TWCIcons
ImageName=Alert.ico
AntiAlias=1
ToolTipIcon=#ImagePath#\TWCIcons\Alert.ico
ToolTipTitle=Severe Weather Alerts
ToolTipWidth=350
ToolTipType=1
Hidden=0
;ImageAlpha=#IconAlpha#
;DynamicVariables=1
LeftMouseUpAction=["https://www.wunderground.com/US/NV/003.html?utm_source=HomeCard&utm_content=Alert&cm_ven=HomeCardAlert&hdf=1"]
MouseOverAction=[!SetOption MeterCurrentIcon ImageAlpha 255][!UpdateMeter MeterCurrentIcon][!Redraw]
MouseLeaveAction=[!SetOption MeterCurrentIcon ImageAlpha #IconAlpha#][!UpdateMeter MeterCurrentIcon][!Redraw]
UpdateDivider=-1


[CurrentConditionsParent]
Measure=Plugin
Group=Weather
Plugin=WebParser
URL=[WeatherForecast]
RegExp=#CurrentConditions#
Disabled=1

[CurrentIconChild]
Measure=Plugin
Group=Weather
Plugin=WebParser
URL=[CurrentConditionsParent]
StringIndex=6
Disabled=1

[MeterCurrentIcon]
Meter=Image
MeasureName=CurrentIconChild
W=135
X=5
Y=-8
ImagePath=#ImagePath#\TWCIcons
PreserveAspectRatio=1
ImageAlpha=#IconAlpha#
AntiAlias=1
DynamicVariables=1
LeftMouseUpAction=["http://www.weather.com/weather/today/l/#LocationCode#"]
MouseOverAction=[!SetOption MeterCurrentIcon ImageAlpha 255][!UpdateMeter MeterCurrentIcon][!Redraw]
MouseLeaveAction=[!SetOption MeterCurrentIcon ImageAlpha #IconAlpha#][!UpdateMeter MeterCurrentIcon][!Redraw]
UpdateDivider=-1

Code: Select all

function Initialize()
	
	weatherParent = SKIN:GetMeasure('WeatherForecast')
	
end

function Update()


	weatherData = weatherParent:GetStringValue()

	alertData = string.match(weatherData, '<feature>(.-)</feature>')

	alertString = '\n'
	startPosition = 1

print (alertData)

	if alertData then
		dummyValue, alertCount = string.gsub(alertData, '(<t>)', "")
		for i = 1, alertCount do
			alertString = alertString .. tostring(i) .. ' - ' .. string.match(alertData, '<t>(.-)</t>', startPosition) .. '\n'
			startPosition = startPosition + string.len(alertString) - string.len(tostring(i)) - 3
		end
		SKIN:Bang('!SetOption', 'MeterAlert', 'Hidden', '0')
		SKIN:Bang('!SetOption', 'MeterAlert', 'ToolTipText', alertString)
	else
		SKIN:Bang('!SetOption', 'MeterAlert', 'Hidden', '1')
		SKIN:Bang('!SetOption', 'MeterAlert', 'ToolTipText', '')
		alertCount = 0
	end
	
	return(alertCount)
	
end
Post Reply