It is currently April 26th, 2024, 2:20 pm

Randomly activated gif

Get help with creating, editing & fixing problems with skins
User avatar
Halloyo
Posts: 31
Joined: June 17th, 2020, 3:08 am

Randomly activated gif

Post by Halloyo »

Hello, I am currently working on a skin based on Neko Atsume. In it, the cats sometimes have a groom animation, but for the most part they are static. Basically, I want to recreate this behaviour and I have managed to do it (measure zero isn't relevant to this problem):

Code: Select all

[Variables]
Zero=0


CatID=00
PoseID=01
FrameNumber=8

[MeasureZero]
Measure=String
String=#FrameNumber#
IfCondition=MeasureZero>9
IfTrueAction=[!SetVariable Zero ""]

[MeasureRandom]
Measure=Calc
Formula=random
LowBound=1
HighBound=100
UpdateRandom=1
UpdateDivider=10
IfCondition=MeasureRandom>20
IfTrueAction=[!SetVariable FrameNumber 1]
IfFalseAction=[!SetVariable FrameNumber 8]
DynamicVariables=1

[ImageNumberCalc]
Measure=Calc
Formula=(Counter % #FrameNumber#)+1
DynamicVariables=1

[Cat01]
Meter=Image
ImageName=#@#Images\Cats\#CatID#_#PoseID#_#Zero#[ImageNumberCalc].png
PreserveAspectRatio=1
DynamicVariables=1
So, if the RNG is smaller than 20, the grooming animation plays. If not, then the cat is in a static pose (the first frame of the gif.) But, if the cat is in its animation cycle and the RNG becomes greater than 20 while it isn't completed, it'll awkwardly jump to the first frame.

What I want to achieve is the following: the cat sometimes play a grooming animation, but it always plays the animation fully before going to a static pose. It should also be possible for the cat to groom itself twice, but I wouldn't mind abandoning the idea if it proves itself too difficult to achieve.

I know I can just increase the RNG update divider, but then the gif would play multiple times, and it wouldn't be guaranteed that the cat would complete its animation cycle.
You do not have the required permissions to view the files attached to this post.
Last edited by Halloyo on June 21st, 2020, 12:56 am, edited 1 time in total.
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Randomly activated gif

Post by mak_kawa »

Hi Halloyo

A quick try...maybe there would be more smart solution, but anyway.

Code: Select all

[Rainmeter]
Update=200

[Variables]
Zero=0


CatID=00
PoseID=01
FrameNumber=8

LoopNum=0

;====================================================================
;				CATS
;====================================================================

[MeasureZero]
Measure=String
String=#FrameNumber#
IfCondition=MeasureZero>9
IfTrueAction=[!SetVariable Zero ""]

[MeasureRandom]
Measure=Calc
Formula=random
LowBound=1
HighBound=100
UpdateRandom=1
UpdateDivider=10
IfCondition=MeasureRandom>20
IfTrueAction=[!SetVariable FrameNumber 1]
IfFalseAction=[!EnableMeasure ImageNumberCalc][!PauseMeasure MeasureRandom]
DynamicVariables=1

[ImageNumberCalc]
Measure=Calc
Formula=(ImageNumberCalc % 8) + 1
IfCondition=[ImageNumberCalc]=8
IfTrueAction=[!SetVariable LoopNum (#LoopNum#+1)]
IfCondition2=#LoopNum#=2
IfTrueAction2=[!SetVariable LoopNum 0][!UnPauseMeasure MeasureRandom][!UpdateMeasure MeasureRandom][!DisableMeasure ImageNumberCalc]
OnUpdateAction=[!SetVariable FrameNumber [ImageNumberCalc]]
DynamicVariables=1
Disabled=1

[Cat01]
Meter=Image
ImageName=#CatID#_#PoseID#_#Zero##FrameNumber#.png
PreserveAspectRatio=1
DynamicVariables=1

[MeterTest1]
Meter=String
MeasureName=MeasureRandom
Y=120
FontSize=24
Antialias=1
* I have removed #@#Images\Cats\ from the ImageName option of [Cat01] for my testing.
User avatar
Halloyo
Posts: 31
Joined: June 17th, 2020, 3:08 am

Re: Randomly activated gif

Post by Halloyo »

Thank you so much! This was precisely what I wanted!
User avatar
balala
Rainmeter Sage
Posts: 16173
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Randomly activated gif

Post by balala »

Halloyo wrote: June 21st, 2020, 12:56 am Thank you so much! This was precisely what I wanted!
Beside mak_kawa's solution, I have a few comments related to the original code:
  • Although [MeasureZero] is not involved into how the skin does work, I'd tempted anyway to rewrite it as a Calc measure, especially that the involved FrameNumber variable is numeric. It is much better to use the IfCondition on a Calc measure, which for sure returns a numeric value, than on a String measure, because the Ifconditions are entirely numeric, strings are not allowed there. So:

    Code: Select all

    [MeasureZero]
    Measure=Calc
    Formula=#FrameNumber#
    IfCondition=MeasureZero>9
    IfTrueAction=[!SetVariable Zero ""]
    DynamicVariables=1
    Here I also added a DynamicVariables=1 option, since the FrameNumber variable is set dynamically, so if you want to use its dynamic value onto this measure, you have to set the dynamic variables on, through the above option (if you have to do this or not, depends on where and how do you want to use this measure).
  • All involved resources (in this case the images) have a better place into the @Resources folder, than in the root folder of your config. In fact I suppose originally they were there (based on the ImageName=#@#Images\Cats\#CatID#_#PoseID#_#Zero#[ImageNumberCalc].png option of the [Cat01] meter), but finally they have been moved to the root folder. Move them back to the (for now) not-existing @Resource folder.
  • If you don't resize the image (since there are no W and H options set on the [Cat01] meter), the PreserveAspectRatio=1 option of the [Cat01] meter makes not too much sense. Recommend to remove it.
All this are applicable to mak_kawa's code as well.
User avatar
Halloyo
Posts: 31
Joined: June 17th, 2020, 3:08 am

Re: Randomly activated gif

Post by Halloyo »

Thank you, I'll change it to a calc measure.

Just out of curiosity, does it change the performance if I do so or is it just so that it avoids potential errors?

(For the images, you're right, but for the purposes of posting to this forum, I created a new folder, and I didn't add width and/or height yet, because I'm still in the testing phase.)
mak_kawa
Posts: 908
Joined: December 30th, 2015, 9:47 am

Re: Randomly activated gif

Post by mak_kawa »

Hi Halloyo

The string measure as [MeasureZero] returns both string and numeric values, so works. But, I think, it is natural that we use the Calc measure to evaluate numeric values using IfCondition, rather than String measure, as balala said. Possibly there is some chance of avoiding potential errors, but no performance change.

BTW, just trivia. If you want to repeat the cat's grooming action for N times, set IfCondition2=#LoopNum#=N. The action can repeat even 1000 times, maybe. :-)
User avatar
balala
Rainmeter Sage
Posts: 16173
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Randomly activated gif

Post by balala »

Halloyo wrote: June 21st, 2020, 10:23 pm Just out of curiosity, does it change the performance if I do so or is it just so that it avoids potential errors?
I suppose (but this is just my supposition, it's not sure at all) that the IfCondition used on a Calc measure uses the least resources. A dev (jsmorley or Brian probably) should tell this exactly.
User avatar
balala
Rainmeter Sage
Posts: 16173
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Randomly activated gif

Post by balala »

mak_kawa wrote: June 22nd, 2020, 12:09 am The string measure as [MeasureZero] returns both string and numeric values, so works.
In fact all measures return both, a numeric and a string value. In most cases these two are the same, but sometimes they are not.
They coincide in case of a Calc or String measure for instance, but are different on a Win7Audio plugin measure.