To be clear, they are global in the context of that Script measure.
Also note that you can't use a variable in Function1() if it is defined in Function2() and Function2 has not been called yet.
It is currently October 13th, 2024, 4:32 pm
Trunc(x)/Franc(x) in lua
-
- Developer
- Posts: 22854
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
-
- Rainmeter Sage
- Posts: 16651
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Trunc(x)/Franc(x) in lua
Oops!!! I missed this small detail I think, but you're perfectly right. Sorry.
I didn't know about the math.modf function. It can be useful I think in some cases. Good to know about it.
-
- Developer
- Posts: 22854
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Trunc(x)/Franc(x) in lua
Well, to be fair, the subject of his post was entirely at conflict with what he asked for in the body of the post.
fract(x) in fact returns the decimal portion of a number as a decimal, so if you go by his post subject, you are right, but in the body he seems to indicate that he wants the decimal portion returned as an integer, which is a horse of a different color.
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
Re: Trunc(x)/Franc(x) in lua
Sorry if I wasn't clear enough, what I'm asking is if I define a variable to be local in a function, will a function called by the first one be able to use that variable?
-
- Developer
- Posts: 22854
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Trunc(x)/Franc(x) in lua
No, not if you define it as "local". You would then have to pass the value as a parameter to the second function.kyriakos876 wrote: ↑November 11th, 2018, 2:28 pm Sorry if I wasn't clear enough, what I'm asking is if I define a variable to be local in a function, will a function called by the first one be able to use that variable?
-
- Rainmeter Sage
- Posts: 16651
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Trunc(x)/Franc(x) in lua
Right. But it was my inattention (sorry for this), because I know I read he wants the decimal part as integer, but finally when I posted my reply, I forgot about this.jsmorley wrote: ↑November 11th, 2018, 1:47 pm Well, to be fair, the subject of his post was entirely at conflict with what he asked for in the body of the post.
fract(x) in fact returns the decimal portion of a number as a decimal, so if you go by his post subject, you are right, but in the body he seems to indicate that he wants the decimal portion returned as an integer, which is a horse of a different color.
Anyway doesn't matter too much, because kyriakos876 wrote in the meantime that the decimal part as decimal is ok.
-
- Developer
- Posts: 22854
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Trunc(x)/Franc(x) in lua
He just likes to make extra work for us by not be at all clear and precise about what he is trying to do... The latest "local" question is another example of this...balala wrote: ↑November 11th, 2018, 2:32 pm Right. But it was my inattention (sorry for this), because I know I read he wants the decimal part as integer, but finally when I posted my reply, I forgot about this.
Anyway doesn't matter too much, because kyriakos876 wrote in the meantime that the decimal part as decimal is ok.
-
- Rainmeter Sage
- Posts: 16651
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Trunc(x)/Franc(x) in lua
I don't comment...
-
- Posts: 919
- Joined: January 30th, 2017, 2:01 am
- Location: Greece
Re: Trunc(x)/Franc(x) in lua
Alright cool. Got it.
I agree, the title might have been a little bit misleading I must say,jsmorley wrote: ↑November 11th, 2018, 1:47 pm Well, to be fair, the subject of his post was entirely at conflict with what he asked for in the body of the post.
fract(x) in fact returns the decimal portion of a number as a decimal, so if you go by his post subject, you are right, but in the body he seems to indicate that he wants the decimal portion returned as an integer, which is a horse of a different color.
But yea, mainly because I didn't know how else I to put it, I used this to better describe it.kyriakos876 wrote: ↑November 10th, 2018, 8:32 pm And if there's one equivalent to the Franc(x) but not exactly... I want as the end result this:
Yup, I'm bad at explaining what I want sometimes... I'm trying to make it simple but it turns out complicated.
Pardon me
-
- Developer
- Posts: 22854
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Trunc(x)/Franc(x) in lua
Here is how it works:
If you have a skin like this:
And Lua like this:
It works fine and returns "25" to the skin.
If you have Lua like this:
That is an error, as myVar1 does not exist in the context of Function2().
You would have to:
In order to pass the "local" value of myVar1 to Function2(arg)
If you have a skin like this:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1
[MeterResult]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=[&Lua:Function1()]
Code: Select all
function Function1()
myVar1 = 5
myVar2 = Function2()
return myVar2
end
function Function2()
return 20 + myVar1
end
If you have Lua like this:
Code: Select all
function Function1()
local myVar1 = 5
myVar2 = Function2()
return myVar2
end
function Function2()
return 20 + myVar1
end
You would have to:
Code: Select all
function Function1()
local myVar1 = 5
myVar2 = Function2(myVar1)
return myVar2
end
function Function2(arg)
return 20 + arg
end