It is currently April 27th, 2024, 7:25 am

[solved] Finding correct variable in a lua script to use in skin bang function

Get help with creating, editing & fixing problems with skins
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

[solved] Finding correct variable in a lua script to use in skin bang function

Post by CodeCode »

These both are great leads. I was trying similar but not setting one step or the other, correctly.

It's almost that hour of the night that becomes morning soon.

Today is tomorrow's yesterday.
Last edited by CodeCode on September 15th, 2023, 7:37 am, edited 1 time in total.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by CodeCode »

SilverAzide wrote: September 14th, 2023, 4:41 pm I think you are overthinking things. There's no looping involved; Smurfier's code can be left untouched so it can do all the hard work for you. To be clear: if you are looking at his code, you are doing it wrong, LOL.

Start with the very simplest thing. Don't try to eat the elephant all in one bite... Create your own function that simply writes an entry into the log.

Code: Select all

function MyFunction()
  print("hello world")
end
Next, add the MouseOverAction to the [HolidayStyle] style meter in the Styles.inc file (or whichever styles file your skin is using).

Code: Select all

[HolidayStyle]
...
MouseOverAction=[!CommandMeasure MyLuaScript "MyFunction()"]
The code assumes you have added a script measure named MyLuaScript, so add that into the Styles.inc file if you have not done so already.

When you refresh the skin, you should see "hello world" show up in the Rainmeter log every time you mouse over a holiday. If that works, then simply expand the function to include the logic needed for your tooltip, as I described above.
Good news. The mouseover test worked as hoped. :thumbup:

Just missing some of the bits to find and show the event name in Smurfier's lua in the new lua. But first I will try a skin:bang !setoption, and will pop back in to let you know further details on progress. :great:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by CodeCode »

Yincognito wrote: September 14th, 2023, 5:08 pm Curly brackets in Lua:
https://stackoverflow.com/questions/686931/are-curly-brackets-used-in-lua

So, they are not used as code block begin and end markers, as explained above. Just add the suggested 'if' before the 'end' of the for loop, and remember to close it with an 'end' as well. You don't have to look elsewhere for info, the script has plenty of 'if's to serve as your inspiration. This won't break the script at all, since you wouldn't change anything in the existing code, just insert your bit there.

I'm on my phone, but something like:

if (Option == 'ToolTipText') then SKIN:Bang('!SetOption', 'YourMeterNameHere', 'Text', Value) end

in a new line inserted before the 'end' of the 'for' loop should do. This obviously is checking the Option in a case sensitive fashion and assumes the meter where you want to set stuff is a String one, but can be adjusted further if needed.

Take into account that the fact that this is the place where you can get what value goes into the tooltip is just my assumption after briefly looking at the code you posted in the other thread, it isn't tested. However, if this works, then you got away easy with Lua, you just need to set stuff properly in plain Rainmeter, as SilverAzide mentioned as well.

Naturally, you can test both suggestions, see which one works and you prefer, and then settle on it accordingly.
This did not work. It broke the skin. I probably am using the wrong thing for 'value'.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2611
Joined: March 23rd, 2015, 5:26 pm

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by SilverAzide »

CodeCode wrote: September 14th, 2023, 9:05 pm Good news. The mouseover test worked as hoped. :thumbup:

Just missing some of the bits to find and show the event name in Smurfier's lua in the new lua.
Good deal! Now you are ready to move ahead...

Now alter the function to add a parameter to pass the name of the meter you are mousing over:

Code: Select all

MouseOverAction=[!CommandMeasure MyLuaScript "MyFunction('#CURRENTSECTION#')"]
I don't know if you need to add DynamicVariables=1 to the style meter; try it without it first, then add it if it doesn't work.

Next, alter your function to accept a string parameter, like this:

Code: Select all

function MyFunction(sMeterName)
  -- "sMeterName" is a variable that must contain the name of the meter that called this function

  -- create a local variable that contains an instance of the meter (this should be the meter showing an event or holiday)
  local holidayDayMeter = SKIN:GetMeter(sMeterName)

  -- create a local variable that contains the tooltip text from the meter (if any)
  local sText = holidayDayMeter:GetOption('ToolTipText')

  if (sText == '') then
    print('No tooltip text found.')
  else
    print('Event = ' .. sText)
  end
end
Now when you mouseover the holiday, you should see the event name in the log. Now you have the basics you need to load everything into your tooltip meter.
Gadgets Wiki GitHub More Gadgets...
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by CodeCode »

SilverAzide wrote: September 14th, 2023, 11:54 pm Good deal! Now you are ready to move ahead...

Now alter the function to add a parameter to pass the name of the meter you are mousing over:

Code: Select all

MouseOverAction=[!CommandMeasure MyLuaScript "MyFunction('#CURRENTSECTION#')"]
I don't know if you need to add DynamicVariables=1 to the style meter; try it without it first, then add it if it doesn't work.

Next, alter your function to accept a string parameter, like this:

Code: Select all

function MyFunction(sMeterName)
  -- "sMeterName" is a variable that must contain the name of the meter that called this function

  -- create a local variable that contains an instance of the meter (this should be the meter showing an event or holiday)
  local holidayDayMeter = SKIN:GetMeter(sMeterName)

  -- create a local variable that contains the tooltip text from the meter (if any)
  local sText = holidayDayMeter:GetOption('ToolTipText')

  if (sText == '') then
    print('No tooltip text found.')
  else
    print('Event = ' .. sText)
  end
end
Now when you mouseover the holiday, you should see the event name in the log. Now you have the basics you need to load everything into your tooltip meter.
This first real look at lua has really actually been productive, in that I have experimented a lot of lua code and gotten a range of results, that if not working - were doing 'something'.
But yes, this is a working example! Got it working perfectly!
:bounce:
In review, I feel that whilst slicing around in Smurfier's code was not successful - I saw similar strategies over the course of this thread between me and SilverAzide, and Yincognito. It gave me some motes of understanding, so that SilverAzide's help was both instructive and productive.

Thanks to You Guys!
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by Yincognito »

CodeCode wrote: September 14th, 2023, 9:08 pm This did not work. It broke the skin. I probably am using the wrong thing for 'value'.
Actually, it did work, in terms of values, and you can see that if you replace the suggested 'if' with printing Option and Value:

print(Option .. ':' .. Value)

and look at the log. The issue is probably the fact that in the initially suggested code, this sets the Option on that meter very fast, iterating through all tooltips for every displayed day. It doesn't react the mouse over yet either, as this is done a single time.

In theory, these values and MeterName should instead be added to a newly created and emptied table, and on mouse over the meter name should be passed to lua so it can pick the right tooltip value for the meter you're on in a short function you can add to lua as well. Except for not doing this using the styles, this is more or less what SilverAzide suggested as well, and which you already got working. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: [solved] Finding correct variable in a lua script to use in skin bang function

Post by CodeCode »

Oh ya, by the way - this skin as a working example of my task tracker variant frankensteined from many scripts I have found or made from/in these forums.

Happy to share. This was mostly for my own needs, so likely not being released in DevArt or elsewhere for the time being.
Last edited by CodeCode on September 15th, 2023, 8:11 am, edited 2 times in total.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
CodeCode
Posts: 1366
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by CodeCode »

Yincognito wrote: September 15th, 2023, 7:47 am Actually, it did work, in terms of values, and you can see that if you replace the suggested 'if' with printing Option and Value:

print(Option .. ':' .. Value)

and look at the log. The issue is probably the fact that in the initially suggested code, this sets the Option on that meter very fast, iterating through all tooltips for every displayed day. It doesn't react the mouse over yet either, as this is done a single time.

In theory, these values and MeterName should instead be added to a newly created and emptied table, and on mouse over the meter name should be passed to lua so it can pick the right tooltip value for the meter you're on in a short function you can add to lua as well. Except for not doing this using the styles, this is more or less what SilverAzide suggested as well, and which you already got working. ;-)
Yep. Like I said - I probably missed something obvious to lua coders, vs my being a neophyte to lua.

But I do thank you since it takes time to scour through other people's code for rainmeter aside from an advanced lua script designed by a dev. :thumbup:
I will be referring back to this skin for lua basics I have yet to memorise, likely for a while. But I am harkened to trying more lua ideas as an expansion to my rainmeter hobby.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Topic Revisited finding correct correct variable in a lua sript to use in skin bang function

Post by Yincognito »

CodeCode wrote: September 15th, 2023, 7:57 am Yep. Like I said - I probably missed something obvious to lua coders, vs my being a neophyte to lua.
Nah, it wasn't your mistake, it was mine. In more complex cases, suggesting things by actually testing the code works better than offering a suggestion after a quick look at the code. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth