It is currently April 27th, 2024, 1:48 am

Click Check in a If Statement.

Get help with creating, editing & fixing problems with skins
User avatar
Lua_sux
Posts: 1
Joined: July 28th, 2019, 2:49 am

Click Check in a If Statement.

Post by Lua_sux »

I just want something as simple as this to work:

Code: Select all

[Rainmeter]
Background=Deersm.png
IfCondition=(1 > 0)
IfTrueAction= [Play "que.wav"]
obviously the above doesn't work, but I dont know why. (I even tried PlayLoop for testing)
I know how to program (in a real language >:P ), but never have I had as much problems with something so simple as this.
I know how to make this work as so:

Code: Select all

[Rainmeter]
Background=Deersm.png
LeftMouseUpAction=Play "que.wav"
however I wanted multiple audio clips to play at a seemingly random pattern. I found this code and tried to implement it into the IfCondition:

Code: Select all

[MeasureCalcy]
Measure=Calc
Formula=(Random)
LowBound=1
HighBound=6
but obviously before i could even use that, i need to get the first problem out of the way.

EDIT: ok, so I have a temp solution

Code: Select all

[MeasureThingy]
Measure=Plugin
Plugin=QuotePlugin
PathName="#CURRENTPATH#"
Subfolders=1
FileFilter=*.wav
UpdateDivider=-1

[Rainmeter]
Background=Deersm.png
;LeftMouseUpAction=Play "sque.wav"
LeftMouseUpAction=[!UpdateMeasure MeasureThingy][PLAY "[MeasureThingy]"]
but this is still not satisfactory for me cuz i need it to only repeat wav files only after all the other wav files have played once. This temp solution allows some files to play more frequent then others.
User avatar
balala
Rainmeter Sage
Posts: 16174
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Click Check in a If Statement.

Post by balala »

Lua_sux wrote: July 28th, 2019, 3:05 am obviously the above doesn't work, but I dont know why. (I even tried PlayLoop for testing)
It doesn't work because the IfCondition statement must and can be used only on measures. It doesn't work nor on meters, nor on the [Rainmeter] (or any other "non-measure") section.
For instance you can move it to the [MeasureCalcy] measure:

Code: Select all

[Rainmeter]
Background=Deersm.png

[MeasureCalcy]
Measure=Calc
Formula=(Random)
LowBound=1
HighBound=6
IfCondition=(1 > 0)
IfTrueAction= [Play "que.wav"]
This will work. But note that the sound file will be played only once, when you load / refresh the skin. Although the condition is still true even later, the IfTrueAction is executed only once. For a new execution, the condition should become false, then true again (or if you add an IfConditionMode=1 option to the measure, the IfTrueAction is executed on each update of the measure - take care, although not in this case, but this can be a very tricky action, an infinite loop can be created).
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Click Check in a If Statement.

Post by jsmorley »

The key to this I think is to get a numeric index of the .wav sound files in some folder. You will do that with the FileView Plugin.

Once you have a numeric index of the files, you can use a Calc measure with the Random function to select and play one of the files from the folder. The UniqueRandom option will ensure each is only played once until all have been played. The Quote Plugin does not have this capability. Quote is "random" in the sense of rolling a pair of dice. Repeats are possible, and with the fewer the number of files to select from, more and more likely. Random/UniqueRandom is "random" in the sense of drawing a card from a deck and discarding it. Repeats are not possible.

To play a random sound on demand, on a click, you could use something like:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
OnRefreshAction=[PlayStop]

[Variables]

[MeasureFolder]
Measure=Plugin
Plugin=FileView
Path=C:\Users\Jeffrey\Sound Files
Extensions=wav
ShowDotDot=0
ShowFolder=0
; The Count option should be large enough, or larger, than the number of files you are likely to ever have in the folder.
Count=200

[MeasureCount]
Measure=Plugin
Plugin=FileView
Path=[MeasureFolder]
Type=FileCount

[MeasureRandom]
Measure=Calc
Formula=Random
LowBound=1
HighBound=[MeasureCount:]
UpdateRandom=1
UniqueRandom=1
DynamicVariables=1
UpdateDivider=-1

[MeasureFile]
Measure=Plugin
Plugin=FileView
Path=[MeasureFolder]
Index=[MeasureRandom:]
Type=FilePath
DynamicVariables=1
UpdateDivider=-1

[MeterFile]
Meter=String
MeasureName=MeasureFile
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Hidden=1

[MeterPlay]
Meter=String
Y=30r
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Play a Sound
LeftMouseUpAction=[!UpdateMeasure MeasureRandom][!UpdateMeasure MeasureFile][Play "[MeasureFile]"][!ShowMeter MeterFile][!UpdateMeter *][!Redraw]


Personally, I would never have a skin that plays any sound on some regular, unattended basis. That would quickly drive me right out of my mind. While I'm doing something else, like playing a game or watching a video, having some skin saying "Hey!" like some annoying Navi from Zelda would have me unloading the skin within minutes. Can it be done? Sure, but ... ick.