It is currently May 3rd, 2024, 1:14 pm

Need help with the Random measure formula

Get help with creating, editing & fixing problems with skins
UndergarmentPhisogue
Posts: 9
Joined: June 16th, 2020, 3:46 pm

Need help with the Random measure formula

Post by UndergarmentPhisogue »

I've been trying to make a simple skin that, each time it's clicked with the mouse, it gets teleported in a random position on the desktop (taking count of the meter's size so that it doesn't clip out of the desktop).

(missed to point to the problem, edit): The MeterString is used to tell me what the current VarNewXPosition has in value, which is the result of MeasureCalcX. The point is, it tells me it's always 0, and it being a smart-ass it knows it's right, so when I click on the skin it teleports it to x=0 y=0.

My code so far has been small variations of this:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!Move (#VarDefaultX#) (#VarDefaultY#)]

[Variables]
VarDefaultX=164
VarDefaultY=470
VarNewXPosition=0
VarNewYPosition=0

[MeasureCalcX]
Measure=Calc
Formula=(Random)
LowBound=0
HighBound=1339
!SetVariable VarNewXPosition "MeasureCalcRandomX"

[MeasureCalcY]
Measure=Calc
Formula=(Random)
LowBound=0
HighBound=588
!SetVariable VarNewYPosition "MeasureCalcRandomY"

[MeterMario]
Meter=Image
ImageName="#@#Delivery Ready to go.png"
LeftMouseUpAction=[!Move (#VarNewXPosition#) (#VarNewYPosition#)]
MiddleMouseUpAction=[!Move (#VarXPosition#) (#VarYPosition#)]

[MeterString]
Meter=String
SolidColor=255, 0, 0, 255
Text=#VarNewXPosition#
(just for context and giggles, the skin's image is: https://imgur.com/xf0739p
and the desktop's background image is: https://imgur.com/06W12OJ )
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Need help with the Random measure formula

Post by jsmorley »

There are several things missing / wrong with that code. Take a look at this:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!Move (#VarDefaultX#) (#VarDefaultY#)]

[Variables]
VarDefaultX=164
VarDefaultY=470
VarNewXPosition=0
VarNewYPosition=0

[MeasureCalcX]
Measure=Calc
Group=Random
Formula=(Random)
LowBound=0
HighBound=1339
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!SetVariable VarNewXPosition "[MeasureCalcX]"]

[MeasureCalcY]
Measure=Calc
Group=Random
Formula=(Random)
LowBound=0
HighBound=588
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!SetVariable VarNewYPosition "[MeasureCalcY]"]

[MeterMario]
Meter=Image
ImageName=#@#Delivery Ready to go.png
DynamicVariables=1
LeftMouseUpAction=[!UpdateMeasureGroup "Random"][!Move (#VarNewXPosition#) (#VarNewYPosition#)]
MiddleMouseUpAction=[!UpdateMeasureGroup "Random"][!Move (#VarXPosition#) (#VarYPosition#)]

[MeterString]
Meter=String
SolidColor=255, 0, 0, 255
Text=#VarNewXPosition#
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16195
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need help with the Random measure formula

Post by balala »

EDIT: Sorry jsmorely, you beat me (again).
UndergarmentPhisogue wrote: July 5th, 2020, 6:08 pm (missed to point to the problem, edit): The MeterString is used to tell me what the current VarNewXPosition has in value, which is the result of MeasureCalcX. The point is, it tells me it's always 0, and it being a smart-ass it knows it's right, so when I click on the skin it teleports it to x=0 y=0.
You can't simply add those !SetVariable bangs to the [MeasureCalcX] and [MeasureCalcY] measures, because you get it never executed. All bangs have to belong to a valid option. For instance add them to two OnChangeAction or OnUpdateAction options:

Code: Select all

[MeasureCalcX]
Measure=Calc
Formula=Random
LowBound=0
HighBound=1339
OnChangeAction=[!SetVariable VarNewXPosition "[MeasureCalcX]"]

[MeasureCalcY]
Measure=Calc
Formula=Random
LowBound=0
HighBound=588
OnChangeAction=[!SetVariable VarNewYPosition "[MeasureCalcY]"]
But a few comments here:
  • None of the two above measures never changes, because for this, they are requiring to add an UpdateRandom=1 option as well to both measures (or alternatively at least a DynamicVariables=1 option).
  • The original !SetVariable bangs were not correct, because:
    • the [MeasureCalcRandomX] and [MeasureCalcRandomY] measures don't exist (this is what were used into the !SetVariable bangs). I suppose the appropriate names should be [MeasureCalcX] and [MeasureCalcY], so I replaced them.
    • the names of the measures (no matter if they are [MeasureCalcRandomX] / [MeasureCalcRandomY] or [MeasureCalcX] / [MeasureCalcY]) have to be used as section variables (have to be included into brackets).
UndergarmentPhisogue
Posts: 9
Joined: June 16th, 2020, 3:46 pm

Re: Need help with the Random measure formula

Post by UndergarmentPhisogue »

Thanks to both, I'll read more on the manual before trying on a new skin :???:
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Need help with the Random measure formula

Post by jsmorley »

UndergarmentPhisogue wrote: July 5th, 2020, 7:49 pm Thanks to both, I'll read more on the manual before trying on a new skin :???:
Feel free to ask if you are not sure about anything. We are glad to help.
UndergarmentPhisogue
Posts: 9
Joined: June 16th, 2020, 3:46 pm

Re: Need help with the Random measure formula

Post by UndergarmentPhisogue »

To be honest, there is:

while trying to add a fade effect, I stumbled upon the fact that it just doesn't wait for it to stop fading out, it just blazes through all the actions like it wins him a new day to live.
What I'm trying to do now is make it fade, (only)after the fading is done it can teleport, and then fade back in:

Code: Select all

[MeterMario]
Meter=Image
ImageName=#@#Delivery Ready to go East.png
DynamicVariables=1
LeftMouseUpAction=[!UpdateMeasureGroup "Random"] [!FadeDuration 1000] [!HideFade] [!Move (#VarNewXPosition#) (#VarNewYPosition#)] [!ShowFade]
MiddleMouseUpAction=[!Move (#VarDefaultX#) (#VarDefaultY#)]
I tried using the [!Delay] bang (after [!HideFade]) with different values (from 1000 to 50 and all the grey zones), but what it did was see it fade out without teleporting, and then never see it back again until a refresh (FadeDuration is a pretty high value, so I could see it die slowly and never see it coming back).

I don't understand why the delay is preventing it from coming back, from Rainmeter's own context menu it shows that the coordinates are still the same, so it isn't moving from there, it's doing everything until [!HideFade] and then zilch.
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Need help with the Random measure formula

Post by jsmorley »

UndergarmentPhisogue wrote: July 5th, 2020, 9:36 pm To be honest, there is:

while trying to add a fade effect, I stumbled upon the fact that it just doesn't wait for it to stop fading out, it just blazes through all the actions like it wins him a new day to live.
What I'm trying to do now is make it fade, (only)after the fading is done it can teleport, and then fade back in:

Code: Select all

[MeterMario]
Meter=Image
ImageName=#@#Delivery Ready to go East.png
DynamicVariables=1
LeftMouseUpAction=[!UpdateMeasureGroup "Random"] [!FadeDuration 1000] [!HideFade] [!Move (#VarNewXPosition#) (#VarNewYPosition#)] [!ShowFade]
MiddleMouseUpAction=[!Move (#VarDefaultX#) (#VarDefaultY#)]
I tried using the [!Delay] bang (after [!HideFade]) with different values (from 1000 to 50 and all the grey zones), but what it did was see it fade out without teleporting, and then never see it back again until a refresh (FadeDuration is a pretty high value, so I could see it die slowly and never see it coming back).

I don't understand why the delay is preventing it from coming back, from Rainmeter's own context menu it shows that the coordinates are still the same, so it isn't moving from there, it's doing everything until [!HideFade] and then zilch.


Well, it works ok for me, with one caveat...

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!Move (#VarDefaultX#) (#VarDefaultY#)]

[Variables]
VarDefaultX=164
VarDefaultY=470
VarNewXPosition=0
VarNewYPosition=0

[MeasureCalcX]
Measure=Calc
Group=Random
Formula=(Random)
LowBound=0
HighBound=1339
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!SetVariable VarNewXPosition "[MeasureCalcX]"]

[MeasureCalcY]
Measure=Calc
Group=Random
Formula=(Random)
LowBound=0
HighBound=588
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!SetVariable VarNewYPosition "[MeasureCalcY]"]

[MeterMario]
Meter=Image
ImageName=#@#Delivery Ready to go East.png
DynamicVariables=1
LeftMouseUpAction=[!UpdateMeasureGroup "Random"] [!FadeDuration 1000][!HideFade][!Delay 1200][!Move (#VarNewXPosition#) (#VarNewYPosition#)] [!ShowFade]
MiddleMouseUpAction=[!UpdateMeasureGroup "Random"][!Move (#VarXPosition#) (#VarYPosition#)]

[MeterString]
Meter=String
SolidColor=255, 0, 0, 255
Text=#VarNewXPosition#
DynamicVariables=1
You have to be sure that the !Delay is set to at least a tad more than !FadeDuration, so it has time to "fade out" fully before it moves the skin and fades it back in. Keep in mind that all stacked-up bangs are "sequential" in the order they are executed, but they don't in any way wait for one to "finish" before executing the next one. They fire off one after the other as quickly as possible, which is REALLY, REALLY quickly indeed. That is the purpose of the !Delay bang. If used carefully and with some thought, it can have things be a bit more heel-to-toe, allowing you to "wait" a defined amount of time between bangs. It's still in no way waiting for anything other than the !Delay bang itself to "finish", but it can be useful.

P.S. What !FadeDuration does is permanently set the value for FadeDuration in Rainmeter.ini, associated with that [ConfigName]. This not only controls how fast bangs like !HideFade / !ShowFade work, but also how fast the skin "loads" and "unloads". You may not want that effect then, so you might consider using !FadeDuration to set it to 1000 when you need it, and then use !FadeDuration again with 250 (the default) at the end of the action.

Code: Select all

LeftMouseUpAction=[!UpdateMeasureGroup "Random"][!FadeDuration 1000][!HideFade][!Delay 1200][!Move (#VarNewXPosition#) (#VarNewYPosition#)][!ShowFade][!FadeDuration 250]
UndergarmentPhisogue
Posts: 9
Joined: June 16th, 2020, 3:46 pm

Re: Need help with the Random measure formula

Post by UndergarmentPhisogue »

Still doing the weird thing :uhuh:, don't understand why it's not working
It just fades out and bye-bye, doesn't reapper, doesn't change coordinates, just isn't visible anymore.

Since it runs all the actions consecutively and not at the same time, I can safely say it's the !Delay bang that's giving it problems; whenever I refresh the skin or unload and reload, when it comes back it still has the delayed fade in, so it's not advancing after "[!Delay 1200]", or whatever other value I put in (tried lower ones, tried higher ones, niet).

I'll have to look into other ways (that don't involve me fidgeting too much with code, I saw some atrocities in other forum posts).
User avatar
balala
Rainmeter Sage
Posts: 16195
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Need help with the Random measure formula

Post by balala »

UndergarmentPhisogue wrote: July 6th, 2020, 7:20 pm Still doing the weird thing :uhuh:, don't understand why it's not working
It just fades out and bye-bye, doesn't reapper, doesn't change coordinates, just isn't visible anymore.
What is your current code? Because more have been posted here, so what are you working with now?
UndergarmentPhisogue
Posts: 9
Joined: June 16th, 2020, 3:46 pm

Re: Need help with the Random measure formula

Post by UndergarmentPhisogue »

Modified some of the variables' names to make them more comprehensible (e.g. the default x and y for when the middle mouse click is pressed), wanted to implement a function to make it flip each teleport randomly (which is commented), and there are more comments regarding the Measures because I wanted to post it on my Deviantart when I finished it:

EDIT: I know that the Delay's lower limit should be 16 milliseconds, I was tinkering with it and forgot it

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=[!Move (#VarDefaultX#) (#VarDefaultY#)]

[Variables]
VarDefaultX=164
VarDefaultY=470
VarNewXPosition=0
VarNewYPosition=0
;VarFlipVisible=0

;(Keep in mind: the skin's position identifies with the top leftmost pixel)
;"Highbound" here is the furthest x coordinate it can teleport to, 121 is the total width of the image to not make it clip outside the desktop
[MeasureCalcX]
Measure=Calc
Group=Random
Formula=(Random)
LowBound=0
HighBound=((#WORKAREAWIDTH#)-121)
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!SetVariable VarNewXPosition "[MeasureCalcX]"]

;(Keep in mind: the skin's position identifies with the top leftmost pixel)
;"Highbound" here is the furthest y coordinate it can teleport to, 140 is the total height of the image to not make it go outside the desktop
;That other value in "Highbound", "40", is the taskbar's height: in Windows 10 default, the DPI is 100% making the taskbar (which is at the bottom) 40 pixels high
[MeasureCalcY]
Measure=Calc
Group=Random
Formula=(Random)
LowBound=0
HighBound=(((#WORKAREAHEIGHT#)-140)-40)
UpdateRandom=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!SetVariable VarNewYPosition "[MeasureCalcY]"]

;Testing for making it flip certain times

;[MeasureCalcFlip]
;Measure=Calc
;Group=Random
;Formula=(Random)
;LowBound=0
;HighBound=1
;UpdateRandom=1
;UpdateDivider=-1
;DynamicVariables=1
;OnUpdateAction=[!SetVariable VarFlipVisible "[MeasureCalcFlip]"]

[MeterMario]
Meter=Image
ImageName=#@#Delivery Ready to go East.png
DynamicVariables=1
LeftMouseUpAction=[!UpdateMeasureGroup "Random"] [!FadeDuration 1000] [!HideFade] [!Delay 15] [!Move (#VarNewXPosition#) (#VarNewYPosition#)] [!ShowFade]
MiddleMouseUpAction=[!UpdateMeasureGroup "Random"][!Move (#VarDefaultX#) (#VarDefaultY#)]

;Meters I used in testing

;[MeterStringPos]
;Meter=String
;SolidColor=255, 0, 0, 255
;Text=#VarNewXPosition#, #VarNewYPosition#
;DynamicVariables=1
;[MeterStringFlip]
;Meter=String
;Y=16
;SolidColor=0, 255, 50, 255
;Text=#VarFlipVisible#
;DynamicVariables=1