It is currently March 28th, 2024, 11:09 pm

I'm not getting the right variable!

Get help with creating, editing & fixing problems with skins
3m0-swag
Posts: 14
Joined: December 25th, 2012, 1:44 am

I'm not getting the right variable!

Post by 3m0-swag »

I'm creating a hex color picker and for one of the buttons it's supposed to copy(in clipboard) the CURRENT hex but instead it keeps copying the previous one. I'm tweaking someone else's lua file to do all the actual code but I've never used Lua before. It only works if I refresh the skin but that resets where your cursor has landed. How do I go about doing this?

Fwi:
The file is supposed to detect what color you selected and then create a variable. In the skin I have a button to copy said variable but it doesn't want to unless it's refreshed.

I'll post whatever is necessary if asked.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: I'm not getting the right variable!

Post by balala »

3m0-swag wrote:I'm creating a hex color picker and for one of the buttons it's supposed to copy(in clipboard) the CURRENT hex but instead it keeps copying the previous one. I'm tweaking someone else's lua file to do all the actual code but I've never used Lua before. It only works if I refresh the skin but that resets where your cursor has landed. How do I go about doing this?

Fwi:
The file is supposed to detect what color you selected and then create a variable. In the skin I have a button to copy said variable but it doesn't want to unless it's refreshed.
First if you didn't do it yet, try to add a DynamicVariables=1 option to the button meter which copes the variable. This option is required if you are setting dynamically the value of the variable.
3m0-swag wrote:I'll post whatever is necessary if asked.
If the above solution doesn't help, please post the code of your skin and the code of the .lua file. Or even better, pack the whole config and upload it.
3m0-swag
Posts: 14
Joined: December 25th, 2012, 1:44 am

Re: I'm not getting the right variable!

Post by 3m0-swag »

Nope, Doesn't work... Here's the skin.
Hex Picker_-0.1 lol.rmskin
Also the "Pick" Button is the copy button. Should've mentioned that before lol
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: I'm not getting the right variable!

Post by balala »

The problem resides in the ColorSpectrum.lua script file. Look for the following lines:

Code: Select all

SKIN:Bang('!SetOption',   t.Meter, t.Option, t.Value)
SKIN:Bang('!UpdateMeter', t.Meter)
and add below them the following ones:

Code: Select all

SKIN:Bang('!SetVariable', 'MyColor', Colors.RGB.Red..','..Colors.RGB.Green..','..Colors.RGB.Blue)
SKIN:Bang('!UpdateMeter', 'BB3')
3m0-swag
Posts: 14
Joined: December 25th, 2012, 1:44 am

Re: I'm not getting the right variable!

Post by 3m0-swag »

Thanks that worked perfectly! But now I'm just realizing how over my head i'm getting.. I need to basically make all of the buttons actually work lol and it is turning out to be way more complex than i thought.. any help would be great. I was just working on the text input button for Red just to get it started but it would need to change a "variable" that was changed by the lua.. wow this is so hard to explain.... basically from start to finish you pick a color then the lua translates that and
1.sets the cursor where you clicked
2.translates the RBG of the color to the skin as text
blah blah blah
i need to also make the + and - keys obviously - and + the RBG!
If only there was a simpler way to do all this.

i'm losing my damn mind... please help :?
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: I'm not getting the right variable!

Post by balala »

3m0-swag wrote:Thanks that worked perfectly! But now I'm just realizing how over my head i'm getting.. I need to basically make all of the buttons actually work lol and it is turning out to be way more complex than i thought.. any help would be great. I was just working on the text input button for Red just to get it started but it would need to change a "variable" that was changed by the lua.. wow this is so hard to explain.... basically from start to finish you pick a color then the lua translates that and
1.sets the cursor where you clicked
2.translates the RBG of the color to the skin as text
blah blah blah
i need to also make the + and - keys obviously - and + the RBG!
If only there was a simpler way to do all this.
Very hard. It's hard, because when you click any of those buttons, you should change the value of the appropriate color, which would update the lua script measure exactly as when you would click on the appropriate point of the image. But at least me, don't know where this point is, for any color and any color component change.
Will try to figure out something, but I'm not sure I'll succeed. Maybe someone else will.
3m0-swag
Posts: 14
Joined: December 25th, 2012, 1:44 am

Re: I'm not getting the right variable!

Post by 3m0-swag »

ANY help with this would be greatly appreciated. If you could possibly help me figure out how to change the lua code to change external variables instead that'd be useful. Or if I was able to get all of the lua code simplified and put into the skin directly than it'd be as simple as
Red = VAR Blue = VAR and so on then have all the variables = ONE rgb variable. That'd be the easiest way of doing it, that way I could simply change the red or whichever and it'd change the red variable and then update the full rgb variable.

Only thing is is I don't understand how lua coding works. Honestly idk any coding aside from a little CSS lol
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: I'm not getting the right variable!

Post by balala »

3m0-swag wrote:ANY help with this would be greatly appreciated. If you could possibly help me figure out how to change the lua code to change external variables instead that'd be useful. Or if I was able to get all of the lua code simplified and put into the skin directly than it'd be as simple as
Red = VAR Blue = VAR and so on then have all the variables = ONE rgb variable. That'd be the easiest way of doing it, that way I could simply change the red or whichever and it'd change the red variable and then update the full rgb variable.

Only thing is is I don't understand how lua coding works. Honestly idk any coding aside from a little CSS lol
I'd completely renounce to the lua script, because I don't see its importance. At least I think what you'd like to achieve with the posted skin could be done even without a lua script. Or maybe there are some hidden features, which I didn't discover yet?
Anyway, a while ago, rbriddickk84 has posted a skin which can pick the appropriate color, without a lua script. Here is his post: https://forum.rainmeter.net/viewtopic.php?p=136802#p136802 (Thanks again to rbriddickk84 for his very good code).
Starting from his code, I rewrote yours to do everything what you had there. Here is the rewritten code, just paste it over the old one:

Code: Select all

[Rainmeter]
Update=1000
MiddleMouseUpAction=[!Refresh]

[Metadata]
Name=TEST2
Author=
Information=
License=Creative Commons BY-NC-SA 3.0
Version=1.0.0

[Variables]
@include=#@#Style.inc
mx=69
my=52
rr=255
gg=0
bb=0
mzpozX=0 
mzpozY=0
fx=#mx#
fTy=#my#
fy=0
rtx=#rr#
gtx=#gg#
btx=#bb#
rx=#rr#
gx=#gg#
bx=#bb#

[BACKGROUND]
Meter=Image
X=0
Y=0
ImageName=test2.png

[EndColorR]
Measure=Calc
Formula=Clamp((#rtx#-#fy#), 0, 255)
OnUpdateAction=[!SetVariable rx "[EndColorR]"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1
UpdateDivider=-1
Group=SetColor

[EndColorG]
Measure=Calc
Formula=Clamp((#gtx#-#fy#), 0, 255)
OnUpdateAction=[!SetVariable gx "[EndColorG]"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1
UpdateDivider=-1
Group=SetColor

[EndColorB]
Measure=Calc
Formula=Clamp((#btx#-#fy#), 0, 255)
OnUpdateAction=[!SetVariable bx "[EndColorB]"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1
UpdateDivider=-1
Group=SetColor

[HeightMeasure]
Measure=Calc
Formula=Trunc((Round(((#fTy#-51)/48), 1))*255)
Group=Colors
OnUpdateAction=[!SetVariable fy "([HeightMeasure])"]
DynamicVariables=1
UpdateDivider=-1

[BaseRed]
Measure=Calc
Group=Colors
IfConditionMode=1
IfCondition=#fx# < 16
IfTrueAction=[!SetVariable rtx 255][!UpdateMeasureGroup "SetColor"]
IfCondition2=(#fx# > 15) && (#fx# < 33)
IfTrueAction2=[!SetVariable rtx ((16-(#fx#-16))*15)][!UpdateMeasureGroup "SetColor"]
IfCondition3=(#fx# > 32) && (#fx# < 67)
IfTrueAction3=[!SetVariable rtx 0][!UpdateMeasureGroup "SetColor"]
IfCondition4=(#fx# > 66) && (#fx# < 85)
IfTrueAction4=[!SetVariable rtx (Trunc((#fx#-67)*15))][!UpdateMeasureGroup "SetColor"]
IfCondition5=#fx# > 84
IfTrueAction5=[!SetVariable rtx 255][!UpdateMeasureGroup "SetColor"]
DynamicVariables=1
UpdateDivider=-1
;This measure controls the basic Red channel calculations. No brightness measured

[BaseGreen]
Measure=Calc
Group=Colors
IfConditionMode=1
IfCondition=#fx# < 16
IfTrueAction=[!SetVariable gtx (#fx#*15)][!UpdateMeasureGroup "SetColor"]
IfCondition2=(#fx# > 15) && (#fx# < 51)
IfTrueAction2=[!SetVariable gtx 255][!UpdateMeasureGroup "SetColor"]
IfCondition3=(#fx# > 50) && (#fx# < 69)
IfTrueAction3=[!SetVariable gtx (Abs((#fx#-68)*15))][!UpdateMeasureGroup "SetColor"]
IfCondition4=#fx# > 68
IfTrueAction4=[!SetVariable gtx 0][!UpdateMeasureGroup "SetColor"]
DynamicVariables=1
UpdateDivider=-1
;This measure controls the basic Green channel calculations. No brightness measured

[BaseBlue]
Measure=Calc
Group=Colors
IfConditionMode=1
IfCondition=#fx# < 34
IfTrueAction=[!SetVariable btx 0][!UpdateMeasureGroup "SetColor"]
IfCondition2=(#fx# < 50) && (#fx# > 33)
IfTrueAction2=[!SetVariable btx ((#fx#-33)*15)][!UpdateMeasureGroup "SetColor"]
IfCondition3=(#fx# > 49) && (#fx# < 86)
IfTrueAction3=[!SetVariable btx 255][!UpdateMeasureGroup "SetColor"]
IfCondition4=(#fx# > 85)
IfTrueAction4=[!SetVariable btx (Trunc(((100-#fx#)/14)*255))][!UpdateMeasureGroup "SetColor"]
DynamicVariables=1
UpdateDivider=-1

[Spectrum]
Meter=Image
X=26
Y=85
W=142
H=95
ImageName=ColorSpectrum.png
UpdateDivider=-1
LeftMouseDownAction=[!SetVariable mzpozX "$MouseX$"][!SetVariable mzpozY "$MouseY$"][!SetVariable fx "$MouseX:%$"][!SetVariable fTy "$MouseY:%$"][!UpdateMeasureGroup "Colors"][!UpdateMeterGroup "ShowColor"][!UpdateMeterGroup "ColorComponents"][!Redraw]
DynamicVariables=1
UpdateDivider=-1

[CLOSE]
Meter=Button
X=294
Y=12
ButtonImage=#@#Close.png

[Tab_1A]
Meter=Button
X=251
Y=50
ButtonImage=#@#+Button.png
LeftMouseUpAction=[!SetVariable rx "(Clamp((#rx#+5),0,255))"][!UpdateMeter "RGB_Red"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1

[Tab_1B]
Meter=Button
X=276
Y=50
ButtonImage=#@#-Button.png
LeftMouseUpAction=[!SetVariable rx "(Clamp((#rx#-5),0,255))"][!UpdateMeter "RGB_Red"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1

[Tab_2A]
Meter=Button
X=251
Y=86
ButtonImage=#@#+Button.png
LeftMouseUpAction=[!SetVariable gx "(Clamp((#gx#+5),0,255))"][!UpdateMeter "RGB_Green"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1

[Tab_2B]
Meter=Button
X=276
Y=86
ButtonImage=#@#-Button.png
LeftMouseUpAction=[!SetVariable gx "(Clamp((#gx#-5),0,255))"][!UpdateMeter "RGB_Green"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1

[Tab_3A]
Meter=Button
X=251
Y=122
ButtonImage=#@#+Button.png
LeftMouseUpAction=[!SetVariable bx "(Clamp((#bx#+5),0,255))"][!UpdateMeter "RGB_Blue"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1

[Tab_3B]
Meter=Button
X=276
Y=122
ButtonImage=#@#-Button.png
LeftMouseUpAction=[!SetVariable bx "(Clamp((#bx#-5),0,255))"][!UpdateMeter "RGB_Blue"][!UpdateMeterGroup "ShowColor"][!Redraw]
DynamicVariables=1

[Tab_4A]
Meter=Button
X=251
Y=158
ButtonImage=#@#+Button.png

[Tab_4B]
Meter=Button
X=276
Y=158
ButtonImage=#@#-Button.png

[BB1]
Meter=Button
X=25
Y=241
ButtonImage=#@#PALETTE.png

[BB3]
Meter=Button
X=217
Y=241
ButtonImage=#@#PICK.png
LeftMouseUpAction=!SetClip "#rx#,#gx#,#bx#"
DynamicVariables=1

[Crosshair]
Meter=String
MeterStyle=Style
FontFace=Arial
FontColor=255,255,255
AntiAlias=1

[RGB_Red]
Meter=String
Text=#rx#
X=210
Y=54
LeftMouseUpAction=[!CommandMeasure "InputRED" "ExecuteBatch 1"]
DynamicVariables=1
Group=ColorComponents

[InputRED]
Measure=Plugin
Plugin=InputText
SolidColor=242,242,242
FontColor=0,0,0
InputNumber=1
FontFace=Arial
FontSize=10
X=210
Y=54
W=28
H=16
DefaultValue=#rx#
FocusDismiss=1
DynamicVariables=1
Command1=[!SetVariable rx "(Clamp($UserInput$,0,255))"][!UpdateMeter "RGB_Red"][!UpdateMeterGroup "ShowColor"][!Redraw]

[RGB_Green]
Meter=String
Text=#gx#
X=210
Y=90
LeftMouseUpAction=[!CommandMeasure "InputGREEN" "ExecuteBatch 1"]
DynamicVariables=1
Group=ColorComponents

[InputGREEN]
Measure=Plugin
Plugin=InputText
SolidColor=242,242,242
FontColor=0,0,0
InputNumber=1
FontFace=Arial
FontSize=10
X=210
Y=90
W=28
H=16
DefaultValue=#gx#
FocusDismiss=1
DynamicVariables=1
Command1=[!SetVariable gx "(Clamp($UserInput$,0,255))"][!UpdateMeterGroup "ShowColor"][!Redraw]

[RGB_Blue]
Meter=String
Text=#bx#
X=210
Y=126
LeftMouseUpAction=[!CommandMeasure "InputBLUE" "ExecuteBatch 1"]
DynamicVariables=1
Group=ColorComponents

[InputBLUE]
Measure=Plugin
Plugin=InputText
SolidColor=242,242,242
FontColor=0,0,0
InputNumber=1
FontFace=Arial
FontSize=10
X=210
Y=126
W=28
H=16
DefaultValue=#bx#
FocusDismiss=1
DynamicVariables=1
Command1=[!SetVariable bx "(Clamp($UserInput$,0,255))"][!UpdateMeterGroup "ShowColor"][!Redraw]

[SelectedColor]
Meter=Image
SolidColor=#rx#,#gx#,#bx#
X=186
Y=197
W=16
H=16
DynamicVariables=1
UpdateDivider=-1
Group=ShowColor

[ColorHEXOUT]
Meter=String
Text=#rx#, #gx#, #bx#
FontFace=Arial
X=3R
Y=8r
StringAlign=LeftCenter
DynamicVariables=1
UpdateDivider=-1
Group=ShowColor
With this code you can set a color with three methods:
  • Clicking the color palete
  • With the + and - buttons
  • Clicking the individual RGB components and entering a new value for them, from the keyboard.
I think this code fixes a lot of the issues of previous one, but maybe there still are some. Please give it a try and let me know if you have any remarks or questions about it.
3m0-swag
Posts: 14
Joined: December 25th, 2012, 1:44 am

Re: I'm not getting the right variable!

Post by 3m0-swag »

wow thanks so much for that but yeah there are still some issues. one is you removed the crosshair that indicates which color your on, the variables are confusing(not a big deal tho) and the output is supposed to be a hex but i think i can work with this. thanks again!

oh i almost forgot there is still one big problem, how do i make the alpha channel work?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: I'm not getting the right variable!

Post by balala »

3m0-swag wrote:one is you removed the crosshair that indicates which color your on
Is easy to put it back, but the problem is that I don't know how to move it properly when you change the color components with the buttons or when you're entering a new value from the keyboard.
To place the crosshair back, add the following meter, after the [Spectrum] meter:

Code: Select all

[Crosshair]
Meter=String
X=(22+#mzpozX#)
Y=(80+#mzpozY#)
FontColor=255,255,255
FontFace=Calibri
FontSize=8
StringStyle=Normal
StringEffect=Shadow
SolidColor=0,0,0,1
AntiAlias=1
StringAlign=Left
AntiAlias=1
Text=+
Hidden=1
DynamicVariables=1
and add before the [!Redraw] bang of the LeftMouseUpAction option of the [Spectrum] meter, the following bangs: [!UpdateMeter "Crosshair"][!ShowMeter "Crosshair"].
Just for any case, the above option, after adding these bangs, will look this way: LeftMouseDownAction=[!SetVariable mzpozX "$MouseX$"][!SetVariable mzpozY "$MouseY$"][!SetVariable fx "$MouseX:%$"][!SetVariable fTy "$MouseY:%$"][!UpdateMeasureGroup "Colors"][!UpdateMeterGroup "ShowColor"][!UpdateMeterGroup "ColorComponents"][color=#FF0000][!UpdateMeter "Crosshair"][!ShowMeter "Crosshair"][/color][!Redraw]
Again, this isn't yet a good solution, because nor the buttons which are changing the color components, nor entering values from the keyboard, won't update the position of the crosshair. Just the click to the [Spectrum] meter will. Will have to try finding a solution for this issue.
3m0-swag wrote:the variables are confusing(not a big deal tho)
I reused the variables of rbriddickk84 (see his post - the link is in my previous reply).
But finally you don't even need to know what those variables are for (I think).
3m0-swag wrote:and the output is supposed to be a hex but i think i can work with this.
This can be done, eg using the Convert Colors Snippet: https://docs.rainmeter.net/snippets/colors/
I also will try to write a solution which doesn't need a lua script, if any simple exists.
3m0-swag wrote:oh i almost forgot there is still one big problem, how do i make the alpha channel work?
Same way as the R, G and B components. Have to add the appropriate LeftMouseUpAction options to the [Tab_4A] and [Tab_4B] meters and a few other sections, plus a variable:
  • First add the Alpha variable to the [Variables] section: Alpha=255.
  • Then add the following two LeftMouseUpAction options (don't remove the existing options, just add these ones), along with the DynamicVariables=1 options:

    Code: Select all

    [Tab_4A]
    ...
    LeftMouseUpAction=[!SetVariable Alpha "(Clamp((#Alpha#+5),0,255))"][!UpdateMeter "RGB_Alpha"][!UpdateMeterGroup "ShowColor"][!Redraw]
    DynamicVariables=1
    
    [Tab_4B]
    ...
    LeftMouseUpAction=[!SetVariable Alpha "(Clamp((#Alpha#-5),0,255))"][!UpdateMeter "RGB_Alpha"][!UpdateMeterGroup "ShowColor"][!Redraw]
    DynamicVariables=1
  • Add the following two sections, below the [InputBLUE] measure:

    Code: Select all

    [RGB_Alpha]
    Meter=String
    Text=#Alpha#
    X=210
    Y=162
    LeftMouseUpAction=[!CommandMeasure "InputALPHA" "ExecuteBatch 1"]
    DynamicVariables=1
    Group=ColorComponents
    
    [InputALPHA]
    Measure=Plugin
    Plugin=InputText
    SolidColor=242,242,242
    FontColor=0,0,0
    InputNumber=1
    FontFace=Arial
    FontSize=10
    X=210
    Y=162
    W=28
    H=16
    DefaultValue=#Alpha#
    FocusDismiss=1
    DynamicVariables=1
    Command1=[!SetVariable Alpha "(Clamp($UserInput$,0,255))"][!UpdateMeterGroup "ShowColor"][!Redraw]
  • Add the Alpha variable to the following options (again, don't remove any existing option, just replace the appropriate ones):

    Code: Select all

    [SelectedColor]
    ...
    SolidColor=#rx#,#gx#,#bx#,#Alpha#
    ...
    
    [ColorHEXOUT]
    ...
    Text=#rx#,#gx#,#bx#,#Alpha#
    ...
  • And finally, using an image editor, remove the value of the Alpha channel (152), existing on the Test2.png image, which is used as background.