It is currently May 7th, 2024, 3:09 pm

Help with writing to file

Get help with creating, editing & fixing problems with skins
smasher511
Posts: 4
Joined: January 17th, 2013, 10:23 am

Help with writing to file

Post by smasher511 »

Hello all,

I'm parsing a data from xml file, where I have some notification info. I have set it up so it displays notifications when there is <count>number bigger than zero</count>, if it is <count>0</count> it hides the notification.

I would like to be able to dismiss these notifications by simply clicking on the number displayed, and for that I would need to write to xml file following data: <count>0</count>

How would I go about that?

Code: Select all

[MeasureGetCalls]
Measure=Plugin
Plugin=Plugins\WebParser
UpdateRate=10
URL=file://C:\ring.xml
RegExp="(?siU)<count>(.*)</count>"


[NumberOfNewCalls]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureGetCalls]
StringIndex=1
IfEqualValue=0
IfEqualAction=[!HideMeter CallBubble][!HideMeter CallCountTXT][!Redraw]
IfAboveValue=0
IfAboveAction=[!ShowMeter CallBubble][!ShowMeter CallCountTXT][!Redraw] 
DynamicVariables=1

[MeasureScript]
Measure=Script
ScriptFile=#@#write.lua





; CALL

[CallIcon]
Meter=Image
ImageName=icons/call.png
x=-45r
y=0r
ImageAlpha=#IconAlpha#
ImageTint=#IconColor#

[CallBubble]
Meter=Image
ImageName=icons/small_circle.png
x=9r
y=-2r
ImageTint=#NotificationColor#
Hidden=1
LeftMouseUpAction=[!HideMeter CallBubble][!HideMeter CallCountTXT][!CommandMeasure MeasureScript Initialize()][!Redraw] 

[CallCountTXT]
MeasureName=NumberOfNewCalls
Meter=STRING
X=8r
Y=2r
StringAlign=Center
FontColor=#NotificationTXTColor#
FontSize=7
FontFace=Arial
AntiAlias=0
StringEffect=Shadow
Hidden=1
LeftMouseUpAction=[!HideMeter CallBubble][!HideMeter CallCountTXT][!CommandMeasure MeasureScript Initialize()][!Redraw] 
And in my lua script is this:

Code: Select all

function Initialize()
local file=io.open(SKIN:MakePathAbsolute('\ring.xml'), 'w')
   if file then
      io.output(file)
      file:write('<count>0</count>')   
   else
      print('Error: Invalid File Path.')
   end
   
   io.close(file)
End
It does not seem to work. Any help would be much appreciated.
thnks
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Help with writing to file

Post by smurfier »

Code: Select all

function Initialize()
   local file=io.open(SKIN:MakePathAbsolute('\ring.xml'), 'w')
   if file then
      file:write('<count>0</count>')
      file:close() 
   else
      print('Error: Invalid File Path.')
   end
end
io.output is not necessary since you already opened the file in write mode. Your last end was capitalized where it should not have been.
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 . . .
smasher511
Posts: 4
Joined: January 17th, 2013, 10:23 am

Re: Help with writing to file

Post by smasher511 »

thanks for the info, I'll def look into it next time, I already went with the solution of running my exe cmd line app to write to file, as I've already used it in my skin before.