It is currently February 19th, 2020, 11:47 am

How to get the value of which line a quote takes from a text file

Share and get help with Plugins and Addons
SilentJ
Posts: 4
Joined: July 3rd, 2017, 9:38 am

How to get the value of which line a quote takes from a text file

Post by SilentJ »

I am trying to make a program that takes a riddle from one text file and the answer from another and hide the answer until a button is pressed, my problem is that I don't know how to know which riddle the plugin has chosen so that it can take the right answer too.
User avatar
balala
Rainmeter Sage
Posts: 9711
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the value of which line a quote takes from a text file

Post by balala »

SilentJ wrote:I am trying to make a program that takes a riddle from one text file and the answer from another and hide the answer until a button is pressed, my problem is that I don't know how to know which riddle the plugin has chosen so that it can take the right answer too.
Not program, but skin (if you're working with Rainmeter).
That's not possible this way, using the Quote Plugin. If it takes certain line of a file, is very hard (practically impossible) to take the same line of another file.
But instead, I'd propose another approach. Both the riddles and the answers should be included into one single file. When the plugin chooses a line of the file, just the riddle (the first part of the chose line) should be shown and when you click the button, should be shown the rest of the line. This would avoid the need of taking the same line of another file, too. Would this be a good approach for your needs?
SilentJ
Posts: 4
Joined: July 3rd, 2017, 9:38 am

Re: How to get the value of which line a quote takes from a text file

Post by SilentJ »

Yes, I thought of that. Only problem is I don't know how to use only a certain part of a string
SilentJ
Posts: 4
Joined: July 3rd, 2017, 9:38 am

Re: How to get the value of which line a quote takes from a text file

Post by SilentJ »

I have them in the same textfile now, parted by a #. I know in languages like pascal you can copy things from a string up until the position of, in this case, a #. Is there a way to do so within rainmeter?
User avatar
balala
Rainmeter Sage
Posts: 9711
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the value of which line a quote takes from a text file

Post by balala »

SilentJ wrote:I have them in the same textfile now, parted by a #. I know in languages like pascal you can copy things from a string up until the position of, in this case, a #. Is there a way to do so within rainmeter?
Yeah, actually there is:

Code: Select all

[Rainmeter]
Update=1000

[Variables]

[StringStyle]
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1

[MeasureQuote]
Measure=Plugin
Plugin=QuotePlugin
PathName=#@#THE-FILE-WITH-THE-RIDDLES-AND-THE-ANSWERS
UpdateDivider=-1

[MeasureRiddle]
Measure=String
String=[MeasureQuote]
RegExpSubstitute=1
Substitute="^(.*)#(.*)$":"\1"
DynamicVariables=1

[MeasureAnswer]
Measure=String
String=[MeasureQuote]
RegExpSubstitute=1
Substitute="^(.*)#(.*)$":"\2"
DynamicVariables=1

[MeterRiddle]
Meter=STRING
MeasureName=MeasureRiddle
MeterStyle=StringStyle
X=0
Y=0
LeftMouseUpAction=[!ShowMeter "MeterAnswer"][!Redraw]

[MeterAnswer]
Meter=STRING
MeasureName=MeasureAnswer
MeterStyle=StringStyle
X=0r
Y=0R
LeftMouseUpAction=[!HideMeter "MeterAnswer"][!UpdateMeasure *][!UpdateMeter "MeterRiddle"][!Redraw]
Hidden=1
The [MeasureQuote] measure gets the lines of the text file. Add the path of the appropriate file into the PathName option of this measure. See that the measure is set to never be updated (due to its UpdateDivider=-1 option). [MeasureRiddle] and [MeasureAnswer] will return the first and respectively the second part of the chosen line (what is before, respectively after the #). This is done by the appropriate Substitute options.
From the two string meters, [MeterRiddle] is shown all the time, but initially [MeterAnswer] is hidden (it is set so, by the Hidden=1 option). When you click the shown riddle, the answer will be shown, due to the LeftMouseUpAction option of the [MeterRiddle] meter). A new click, this time on the answer, will hide the answer and will update the [MeasureQuote] measure (and in paralel the other two measures, too).
I also added here a [StringStyle] section, to not have to write the same options for both string meters.
Please let me know if this code looks like what you needed.
SilentJ
Posts: 4
Joined: July 3rd, 2017, 9:38 am

Re: How to get the value of which line a quote takes from a text file

Post by SilentJ »

Thank you so much! This is perfect. :thumbup:
User avatar
balala
Rainmeter Sage
Posts: 9711
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to get the value of which line a quote takes from a text file

Post by balala »

SilentJ wrote:This is perfect. :thumbup:
I'm glad if you like it.