balala wrote: ↑November 17th, 2019, 7:21 am
Let's clarify for first what are we talking about. Both jsmorley and me were talking about regular expression substitution (done with a RegExSubstitute and a Substitute options added to the measure). This is working on any kind of measure. This technique can be used for instance to add leading zeros in front of a number when you want to show that number through a String meter.
For instance let's take the following Time measure:
Code: Select all
[MeasureSecond]
Measure=Time
Format=%#S
This measure returns the number of seconds with no leading zero. If now you add a
RegExpSubstitute=1 and a
Substitute="^(.)$":"00\1","^(..)$":"0\1" options to the above [MeasureSecond] measure, you'll get the result with three digits: if the number of seconds has one single digit there will be added two zeros in front of it, while it has two digits, one single zero will be added. Both cases you get the result with three digits (even if this doesn't make too much sense). No String measure involved, however the regular expression substitution still works. Same way works with WebParser measures, or even with Calc ones.
Believe us, this works not just with String measure.
If you want to add leading zeroes, I have a better example of a regex
here.
I know you can use regex substitute on any measure. I didn't know you could make a measure that only returns numbers have a string value with a substitute, but that still doesn't make a calc measure as powerful as a string measure. Calc measures can not be arrays - at least not in the same cpu time as a string measure. You could in theory replace the whole calc measure with a string as the first substitute and then work exactly the same way, but there's no direct benefit, it just costs an extra substitution. (Though having the separated number/object output could potentially be useful in some cases but this is a bit of a tangent)
Take the following code as an example;
We first create an array/object type thing in a reasonably human readable format, then we convert that human readable object into a string with the escaped variable names using the [EntityLoader] measure regex, and then finally resolve all the variables in the [Entities] measure to turn it into a regex readable string:
X9Y9NSlime1|X8Y6NSlime2|X12Y4NSlime3|X1Y4NBox1|X5Y6NBox2|
We can then check if an entity is at position X/Y by passing the X and Y coordinates to the ToBeCheckedX and ToBeCheckedY variables and updating the [CheckEntityCollisions] measure. Then if that entity exists, we can access its variables through nested variables like
[#[&CheckEntityCollisions]X] effectively turning Rainmeter ini files into something almost resembling OOP.
Code: Select all
[variables]
; Entity stuff
Entities = Slime1|Slime2|Slime3|Box1|Box2
; Entities need to be manually placed in the world for now.
; Give them an X, a Y, Entity type and an Image
; 0 = Pushed on collision
; 1 = battle (not currently implemented)
Slime1X = 9
Slime1Y = 9
Slime1Type = 1
Slime1Image = Slime
Slime2X = 8
Slime2Y = 6
Slime2Type = 1
Slime2Image = Slime
Slime3X = 12
Slime3Y = 4
Slime3Type = 1
Slime3Image = Slime
Box1X = 1
Box1Y = 4
Box1Type = 0
Box1Image = Box
Box2X = 5
Box2Y = 6
Box2Type = 0
Box2Image = Box
[EntityLoader]
Measure = String
String = #Entities#
Group = EntityUpdate
DynamicVariables = 1
RegExpSubstitute = 1
Substitute = "(.*?)(\||$)" : "X[#\1X]Y[#\1Y]N\1|"
[Entities]
Measure = String
String = [&EntityLoader]
Group = EntityUpdate
DynamicVariables = 1
[CheckEntityCollisions]
Measure = String
String = [Entities]
Group = NoUpdate
Disabled = 1
DynamicVariables = 1
RegExpSubstitute = 1
Substitute = ".*?X#ToBeCheckedX#Y#ToBeCheckedY#N(.*?)\|.*" : "\1"
IfMatchMode = 1
IfMatch = "\|"
IfMatchAction = [!UpdateMeasureGroup CollisionCheckers]
IfNotMatchAction = [!UpdateMeasure HandleEntityCollisions]
So. Can you use a regex on any measure? Yes, of course you can. Does it let you do things like this? No.
Was I wrong in saying string measures are the only measures that can do this? Yes. Webparser can do the same thing but requires one extra measure and significantly more cpu time + logic, and time measures can do the same thing in probably very slightly more cpu time, but the same logic. (And any measure EXCEPT a top level parent web parser can do the same thing by wasting the first substitute to pass the string to the measure, technically.)
Being able to output both a number and a string in one measure as jsmorley pointed out is extremely cool, though. I have no idea how it'll be useful, but I'm sure I'll use it someday.
But believe me, arbitrary strings + regex substitute is what makes regex powerful in rainmeter. Regex with predetermined outputs like time, cpu, loop, etc is NOT the same thing, and is significantly less versatile although still quite powerful. Just not to nearly the same degree as with a measure supporting arbitrary strings because those measures just enter an entirely different league of utility, opening up so many more options.