It is currently January 30th, 2023, 10:44 am

Can't get GetString() fired

Share and get help with Plugins and Addons
Posts: 1
Joined: July 22nd, 2017, 9:26 am

Can't get GetString() fired

Post by PumpkinVS »

Hello guys,

*hoping I'm in the right place to ask this*

I recently began working on a plugin for Rainmeter (my first one) and I face a problem with GetString()

Update() works pretty well for me, but I can't make GetString() work.

I looked at Rainmeter plugin exampls (Plugin System Version) and I don't understand how Rainmeter knows when to call it. All my tests are not conclusive è.é

Could you guys enlighten me a bit, please ? :)

Thanks !
User avatar
Posts: 2561
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Can't get GetString() fired

Post by Brian »

A measure essentially has 2 values. A string value and a number value. GetString() will return the string value and is optional. Update() will return the numeric value and is required. Update() is only called once per update cycle, while GetString() can be called multiple times during the update cycle depending on where it was called from.

For example:

Code: Select all

IfMatchAction=[!SomeBang ...]
IfTrueAction=[!SomeOtherBang ...]


Text=%1 - [MyPlugin] - [MyPlugin:]
So what happens here is during the 'update' cycle is Update() (in the MyPlugin plugin) will get called first and return a numeric value (this value is stored by the measure and retrieved later when needed). Then the IfCondition gets processed next and will use the numeric value of the plugin (Update() does not get called again, it uses the stored number value processed during the Update() function). Then the IfMatch gets processed and specifically tests the string value. This is where GetString() is first called. The next part to get updated is the MyCalc measure. Since Calc's work with numeric values, that is what is used here. Next the string meter gets updated and calls the GetString() function of the plugin again - not just once, but twice. The first time is when the percent encoded %1 part of the Text option is parsed. The second is when the section variable [MyPlugin] is parsed. Lastly, a third reference to the plugin is used, but to get the number value and not the string value [MyPlugin:].

Hopefully that makes a little more sense as to 'when' the GetString() value is called.
Note: It is important to not do any 'work' during the GetString() function since it can be called multiple times during the update cycle of a skin. You don't want your string to change for every call to GetString(). Do the work in the Update() function and store it for retrieval in the GetString() function. If you want to return a string in some situations and return the number value in other situations, then in your GetString() function return nullptr (or NULL) for the situations you want the number value to be used.

Check out the SysInfo plugin for a reference to this:
Note: GetString() will return a string for only the 'types' that are strings, else it will return a nullptr - which tells Rainmeter to use the numeric value instead (the one returned in Update()).