It is currently December 7th, 2021, 12:16 pm

SKIN:Bang not working

Help with creating, editing & fixing problems with skins
FlightlessAz
Posts: 24
Joined: September 14th, 2021, 10:27 am

Re: SKIN:Bang not working

Post by FlightlessAz »

death.crafter wrote: October 14th, 2021, 9:40 am Lua doesn't really care where a function is defined. So that isn't a problem here. The problem is that the OP is returning before his work is done. Once return is used, function stops there and returns whatever is in parameter.



Actually no. You can use usual bangs too. And in my opinion, this is not quite efficient to break up a statement if you could write it in one line.

However, the above syntax is quite useful if you are trying to use lua values as parameters to the bang.

Also to the OP.

Have you considered using inline variables as value to the string meter you are using?

If you use an inline variable e.g. [&YourLuaScript:cperiod()], then you can skip the return part in Update.

Also, if you feel like cperiod is a quite heavy function, then you should not use it as a section variable and use what I described in the previous post.
I never thought of this, as I only have limited knowledge of lua and rainmeter code, so I tried following your suggestion. It works, but when the value/string of the cperiod() changes, it doesn't visually show in the meter the change. Only does it change when I manually refresh the skin.
User avatar
death.crafter
Rainmeter Sage
Posts: 1206
Joined: April 24th, 2021, 8:13 pm

Re: SKIN:Bang not working

Post by death.crafter »

FlightlessAz wrote: October 14th, 2021, 1:05 pm I never thought of this, as I only have limited knowledge of lua and rainmeter code, so I tried following your suggestion. It works, but when the value/string of the cperiod() changes, it doesn't visually show in the meter the change. Only does it change when I manually refresh the skin.
Actually you need dynamicvariables=1 on the meter where you use this value. Also your skin needs to have a reasonable update, say 1000. This will work, or you may post the code here.

I can't get to my pc for next some days. So you need to post the code here. Don't forget to use the code tags. The </> button up there.
from the Realm of Death
FlightlessAz
Posts: 24
Joined: September 14th, 2021, 10:27 am

Re: SKIN:Bang not working

Post by FlightlessAz »

death.crafter wrote: October 14th, 2021, 1:57 pm Actually you need dynamicvariables=1 on the meter where you use this value. Also your skin needs to have a reasonable update, say 1000. This will work, or you may post the code here.

I can't get to my pc for next some days. So you need to post the code here. Don't forget to use the code tags. The </> button up there.
When I tried your earlier suggestion, I already had dynamicvariables=1 in the meter displaying the string. Here is the code, as you requested.

scrolling-text-test.lua:

Code: Select all

function tomin(h,m)
	return ((h*60) + m)
end

--function initialize()
--end

wday = os.date('%a')
--wday = 'Fri'
timemin = os.date('%H')*60 + os.date('%M')
--timemin = tomin(16,0)
Subj = {'Physical Education and Health 1', 'Oral Communication in Context', 'Earth Science and Life Science', 'General Mathematics', 'Introduction to Innovating Technology Solutions',	'Personality Development'}
Break = 'Break Time'
Lunch = 'Lunch Break'
goodwork = 'お疲れ様でした!'
x = 6
Mperiod = {timemin >= tomin(7,30) and timemin < tomin(8,30), timemin >= tomin(8,30) and timemin < tomin(9,0), timemin >= tomin(9,0) and timemin < tomin(12,0), timemin >= tomin(13,0) and timemin < tomin(16,0), timemin >= tomin(16,0) and timemin < tomin(17,30), timemin >= tomin(17,30) and timemin < tomin(17,35)}
Tperiod = {timemin >= tomin(7,30) and timemin < tomin(12,0), timemin >= tomin(13,0) and timemin < tomin(17,30), timemin >= tomin(17,30) and timemin < tomin(17,35)}
Wperiod = {timemin >= tomin(7,30) and timemin < tomin(8,45), timemin >= tomin(8,45) and timemin < tomin(9,0), timemin >= tomin(9,0) and timemin < tomin(12,0), timemin >= tomin(13,0) and timemin < tomin(16,0), timemin >= tomin(16,0) and timemin < tomin(16,30), timemin >= tomin(16,30) and timemin < tomin(18,30), timemin >= tomin(18,30) and timemin < tomin(18,35)}
THperiod = {timemin >= tomin(7,30) and timemin < tomin(12,0), timemin >= tomin(13,0) and timemin < tomin(17,30), timemin >= tomin(17,30) and timemin < tomin(20,54)}
Fperiod = {timemin >= tomin(7,30) and timemin < tomin(9,0), timemin >= tomin(9,0) and timemin < tomin(12,0), timemin >= tomin(13,0) and timemin < tomin(16,0), timemin >= tomin(16,0) and timemin < tomin(16,5)}

--function Update()
--	return cperiod()
--end

function Update()
	return Cperiod()
	--SKIN:Bang('[!UpdateMeter ScrollingText][!UpdateMeter ScrollingText][!UpdateMeter ScrollingText]')
end

function Mon()
	if Mperiod[1] then
		return Subj[1]
	elseif Mperiod[2] then
		return Break
	elseif Mperiod [3] then
		return Subj[2]
	elseif Mperiod [4] then
		return Subj[3]
	elseif Mperiod[5] then
		return Subj[4]
	elseif Mperiod[6] then
		return goodwork
	else
		return false
	end
end

function Tue()
	if Tperiod[1] then
		return Subj[5]
	elseif Tperiod[2] then
		return Subj[6]
	elseif Tperiod[3] then
		return goodwork
	else
		return false
	end
end

function Wed()
	if Wperiod[1] then
		return Subj[1]
	elseif Wperiod[2] then
		return Break
	elseif Wperiod [3] then
		return Subj[2]
	elseif Wperiod [4] then
		return Subj[3]
	elseif Wperiod[5] then
		return Break
	elseif Wperiod[6] then
		return Subj[4]
	elseif Wperiod[7] then
		return goodwork
	else
		return false
	end
end

function Thu()
	if THperiod[1] then
		return Subj[5]
	elseif THperiod[2] then
		return Subj[6]
	elseif THperiod[3] then
		return goodwork
	else
		return false
	end
end

function Fri()
	if Fperiod[1] then
		return Subj[4]
	elseif Fperiod [2] then
		return Subj[2]
	elseif Fperiod [3] then
		return Subj[3]
	elseif Fperiod [4] then
		return goodwork
	else
		return false
	end
end

function Schchk()
	if wday == 'Sun' or wday == 'Sat' then
		return false
	elseif timemin >= tomin(0,0) and timemin < tomin(7,30) then
		return false
	elseif wday == 'Mon' or wday == 'Tue' or wday == 'Thu'then
		if timemin >= tomin(17,30) then
			return false
		else
			return true
		end
	elseif wday == 'Wed' then
		if timemin >= tomin(18,30) then
			return false
		else
			return true
		end
	else
		if timemin >= tomin(16,00) then
			return false
		else
			return true
		end
	end
end

function Cperiod(x)
	if x == nil then
		if Schchk() == true then
			if wday == 'Mon' then
				return Mon()
			elseif wday == 'Tue' then
				return Tue()
			elseif wday == 'Wed' then
				return Wed()
			elseif wday == 'Thu' then
				return Thu()
			else
				return Fri()
			end
		else
			return 'Crazy'
		end
	end
end

print(Thu())
scrolling-text-test.ini:

Code: Select all

;font length = 52

[Rainmeter]
Update=#Update#
;BackgroundMode=2
AccurateText=1
SolidColor=200, 200, 200, 50
DynamicWindowSize=1
SkinWidth=838

[Variables]
Include=settei.inc
Update=15
;673
OriginalX=931
Y1=60
Bruh=Bruh Moment
BreakTime="休み時間"
Lunch=昼食時間
StaticText=Bruh
CurrentSubj=#StaticText#
ClassEnd=授業が終わりました。お疲れ様でした!
Leength=[MeterLength:W]
FontColor=255,0,0,255
SpeedMultiplier=3

[mScript]
Measure=Script
ScriptFile=scrolling-text-test.lua
;[DisplayPeriod]
;MeasureName=mScript
;AntiAlias=1
;DynamicVariables=1
;Meter=String
;FontColor=50,50,255,255
;FontFace=KH Dot Hibiya 32
;FontWeight=900
;Fontsize=75
;StringAlign=LeftCenter
;Meter=Image
;SolidColor=80,80,80,0
;Y=70

[TimeZZ]
DynamicVariables=1
;Measure=Calc
;Formula=50600
Measure=Time
Format=%w%H%M

[PeriodDetermine]
DynamicVariables=1
Measure=Calc
Formula=TimeZZ

[TotalMove]
DynamicVariables=1
Measure=Calc
Formula=(([MeterLength:W]+156)*3)
;Formula=3000

[MeterLength]
DynamicVariables=1
;MeasureName=mScript
Text=#CurrentSubj#
FontSize=75
FontFace=KH Dot Hibiya 32
FontWeight=900
FontColor=0,0,0,0
Meter=String

[MeasureMove]
DynamicVariables=1
Measure=Calc
Formula=#OriginalX#-((((Counter)*#SpeedMultiplier#))%[TotalMove])
AverageSize=1

[MeasureMove2]
DynamicVariables=1
Measure=Calc
Formula=#OriginalX#-((((((Counter)*#SpeedMultiplier#))%[TotalMove])+[MeterLength:W]+156)%[TotalMove])

[MeasureMove3]
DynamicVariables=1
Measure=Calc
Formula=#OriginalX#-((((((Counter)*#SpeedMultiplier#))%[TotalMove])+([MeterLength:W]*2)+312)%[TotalMove])
;Formula=0

[Motor]
Measure=Calc
Formula=(Counter%2)
IfBelowValue=1
IfBelowAction=!Execute [!MoveMeter [MeasureMove] #Y1# ScrollingText]
IfEqualValue=1
IfEqualAction=!Execute [!MoveMeter [MeasureMove] #Y1# ScrollingText]
DynamicVariables=1

[Motor2]
Measure=Calc
Formula=(Counter%2)
IfBelowValue=1
IfBelowAction=!Execute [!RainmeterMoveMeter [MeasureMove2] #Y1# ScrollingText2]
IfEqualValue=1
IfEqualAction=!Execute [!RainmeterMoveMeter [MeasureMove2] #Y1# ScrollingText2]
DynamicVariables=1

[Motor3]
Measure=Calc
Formula=(Counter%2)
IfBelowValue=1
IfBelowAction=!Execute [!RainmeterMoveMeter [MeasureMove3] #Y1# ScrollingText3]
IfEqualValue=1
IfEqualAction=!Execute [!RainmeterMoveMeter [MeasureMove3] #Y1# ScrollingText3]
DynamicVariables=1

[MeterBackground]
Meter=Image
X=0
Y=0
W=673
H=120
SolidColor=80,80,80,0

[ScrollingText]
DynamicVariables=1
AntiAlias=1
Meter=String
X=0
Y=60
FontColor=#FontColor#
FontFace=KH Dot Hibiya 32
FontWeight=900
Fontsize=75
StringAlign=LeftCenter
MeasureName=mScript
;Text=#CurrentSubj#
AverageSize=100

[ScrollingText2]
AntiAlias=1
DynamicVariables=1
Meter=String
Text=#CurrentSubj#
X=0
Y=60
W=500
FontColor=#FontColor#
FontFace=KH Dot Hibiya 32
FontWeight=900
Fontsize=75
StringAlign=LeftCenter
MeasureName=mScript

[ScrollingText3]
AntiAlias=1
DynamicVariables=1
Meter=String
X=0
Y=60
W=500
FontColor=#FontColor#
FontFace=KH Dot Hibiya 32
FontWeight=900
Fontsize=75
StringAlign=LeftCenter
Text=#CurrentSubj#
Meter=Image
X=0
Y=0
W=673
H=120
SolidColor=80,80,80,0

;[MeterTime]
;DynamicVariables=1
;Meter=String
;MeasureName=TimeZZ
;FontColor=255,255,0,255
As of now, I only made it so only the [ScrollingText] meter is displaying the string from the lua script.
FlightlessAz
Posts: 24
Joined: September 14th, 2021, 10:27 am

Re: SKIN:Bang not working

Post by FlightlessAz »

death.crafter wrote: October 14th, 2021, 1:57 pm Actually you need dynamicvariables=1 on the meter where you use this value. Also your skin needs to have a reasonable update, say 1000. This will work, or you may post the code here.

I can't get to my pc for next some days. So you need to post the code here. Don't forget to use the code tags. The </> button up there.
is Update=15 reasonable? because my skin requires it to update that fast.
User avatar
balala
Rainmeter Sage
Posts: 13528
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: SKIN:Bang not working

Post by balala »

FlightlessAz wrote: October 15th, 2021, 2:29 am Here is the code, as you requested.

scrolling-text-test.lua:


scrolling-text-test.ini:
Note a mistake in the code of the scrolling-text-test.lua script. The Cperiod function requires a parameter (being defined this way: function Cperiod(x)). But when you're calling it in the Update() function, the parameter is missing. Accordingly the function doesn't work correctly.
FlightlessAz wrote: October 15th, 2021, 2:29 am As of now, I only made it so only the [ScrollingText] meter is displaying the string from the lua script.
So far the skin is showing the running string. What else should it do?
FlightlessAz wrote: October 15th, 2021, 2:30 am is Update=15 reasonable? because my skin requires it to update that fast.
No, in fact it isn't, because the lowest effective value for the Update option is 16. Lower values are not admitted, however if you use a lower one, the skin works as with Update=16, so this doesn't cause trouble. But Update=15 is not a valid value. For details see the second paragraph here.
User avatar
death.crafter
Rainmeter Sage
Posts: 1206
Joined: April 24th, 2021, 8:13 pm

Re: SKIN:Bang not working

Post by death.crafter »

FlightlessAz wrote: October 15th, 2021, 2:29 am
Actually your lua script looked a little flawed to me for various reasons. So I made some changes to it.

First thing was that you were performing actions on a stationary value of timemin and wday, which I turned into functions, so that would return the current time whenver called.

Also you were doing things in a little clumsy and redundant way, which is not an problem but cleaning up your code and reducing redundancy can help another person understand your code a little more efficiently.

Anyway that's not the issue. So here is a modified version of your code. I didn't write all the things but it's an outline.

I was editing your script on phone, so it might not be fully correct. Do yo can check it if you want to do it this way.

Code: Select all

function tomin(h,m)
	return ((h*60) + m)
end

function isBetween(time, lLimit, uLimit)
        return (time >= tomin(lLimit[1], lLimit[2]) and time < tomin(uLimit[1], uLimit[2]))
end

wday = function() return os.date('%a') end
timemin = function() return (os.date('%H')*60 + os.date('%M')) end

Subj = {
        'Physical Education and Health 1',
        'Oral Communication in Context',
        'Earth Science and Life Science',
        'General Mathematics',
        'Introduction to Innovating Technology Solutions',
        'Personality Development'
}

Break = 'Break Time'
Lunch = 'Lunch Break'
goodwork = 'お疲れ様でした!'
x = 6

Mperiod = {
        function() return isBetween(timemin(), {7, 30}, {8, 30}) end,
        function() return isBetween(timemin(), {8, 30}, {9, 0}) end,
        function() return isBetween(timemin(), {9, 0}, {12, 0}) end,
        function() return isBetween(timemin(), {13, 0}, {16, 0}) end,
        function() return isBetween(timemin(), {16, 0}, {17, 30}) end,
        function() return isBetween(timemin(), {17, 30}, {17, 45}) end
}

function Update()
	return Cperiod()
end

function Mon()
	if Mperiod[1]() then
		return Subj[1]
	elseif Mperiod[2]() then
		return Break
	elseif Mperiod[3]() then
		return Subj[2]
	elseif Mperiod[4]() then
		return Subj[3]
	elseif Mperiod[5]() then
		return Subj[4]
	elseif Mperiod[6]() then
		return goodwork
	else
		return false
	end
end

function Schchk()
	if wday() == 'Sun' or wday() == 'Sat' then
		return false
	elseif isBetween(timemin(), {0, 0}, {7, 30}) then
		return false
	elseif wday() == 'Mon' or wday == 'Tue' or wday() == 'Thu' then
		if timemin() >= tomin(17,30) then
			return false
		else
			return true
		end
	elseif wday() == 'Wed' then
		if timemin() >= tomin(18,30) then
			return false
		else
			return true
		end
	else
		if timemin() >= tomin(16,00) then
			return false
		else
			return true
		end
	end
end

function Cperiod()
	if Schchk() == true then
		if wday == 'Mon' then
			return Mon()
		elseif wday == 'Tue' then
			return Tue()
		elseif wday == 'Wed' then
			return Wed()
		elseif wday == 'Thu' then
			return Thu()
		else
			return Fri()
		end
	else
		return 'Crazy'
	end
end
And get rid of the !ExecuteBang and Rainmeter from your bangs. They are long deprecated. I can't check the Rainmeter code now since I am not able to get hold of my pc but I will as soon as I can.
from the Realm of Death
User avatar
death.crafter
Rainmeter Sage
Posts: 1206
Joined: April 24th, 2021, 8:13 pm

Re: SKIN:Bang not working

Post by death.crafter »

balala wrote: October 15th, 2021, 5:40 pm Note a mistake in the code of the scrolling-text-test.lua script. The Cperiod function requires a parameter (being defined this way: function Cperiod(x)). But when you're calling it in the Update() function, the parameter is missing. Accordingly the function doesn't work correctly.
That's not an mistake actually. It's probably the OP trying to debug his code or an desperate measure taken when nothing was working.

Just an observation since the OP is comparing the value to null, that is if you actually give it a parameter, it won't work.
from the Realm of Death
FlightlessAz
Posts: 24
Joined: September 14th, 2021, 10:27 am

Re: SKIN:Bang not working

Post by FlightlessAz »

balala wrote: October 15th, 2021, 5:40 pm Note a mistake in the code of the scrolling-text-test.lua script. The Cperiod function requires a parameter (being defined this way: function Cperiod(x)). But when you're calling it in the Update() function, the parameter is missing. Accordingly the function doesn't work correctly.

So far the skin is showing the running string. What else should it do?
The reason for the first paragraph was because I was following death.crafter's suggestion to call the Cperiod() function inline in the .ini file. If i didn't put any parameter in the function, then it would only display [&mScript:Cperiod()] instead of the value/string of Cperiod() itself.

As for your second paragraph, depending on the time of the day, the string Cperiod() displays changes. What I wanted it to do was for the meter displaying the string of Cperiod() to automatically show the change visually. However, that only happens when I manually refresh the skin itself. Instead, it continues to display the previous string it displayed when it's supposed to change. For example, a certain string "a" is returned by Cperiod() when the time is 8:00 am and 9:00 am, and then between 9:00 am to 10:00 am, another string "b" is returned. The problem is, let us say it is currently 8:59 am, then the meter displays string "a," no problem. However, when the time turns to 9:00 am, when it's supposed to display string "b," it stays at string "a" until I manually refresh the skin itself.
balala wrote: October 15th, 2021, 5:40 pm No, in fact it isn't, because the lowest effective value for the Update option is 16. Lower values are not admitted, however if you use a lower one, the skin works as with Update=16, so this doesn't cause trouble. But Update=15 is not a valid value. For details see the second paragraph here.
I see, I wasn't informed about this.
User avatar
death.crafter
Rainmeter Sage
Posts: 1206
Joined: April 24th, 2021, 8:13 pm

Re: SKIN:Bang not working

Post by death.crafter »

FlightlessAz wrote: October 16th, 2021, 1:35 am As for your second paragraph, depending on the time of the day, the string Cperiod() displays changes. What I wanted it to do was for the meter displaying the string of Cperiod() to automatically show the change visually. However, that only happens when I manually refresh the skin itself. Instead, it continues to display the previous string it displayed when it's supposed to change. For example, a certain string "a" is returned by Cperiod() when the time is 8:00 am and 9:00 am, and then between 9:00 am to 10:00 am, another string "b" is returned. The problem is, let us say it is currently 8:59 am, then the meter displays string "a," no problem. However, when the time turns to 9:00 am, when it's supposed to display string "b," it stays at string "a" until I manually refresh the skin itself.
I think you missed my post.

https://forum.rainmeter.net/viewtopic.php?p=199092#p199092
from the Realm of Death
FlightlessAz
Posts: 24
Joined: September 14th, 2021, 10:27 am

Re: SKIN:Bang not working

Post by FlightlessAz »

death.crafter wrote: October 16th, 2021, 5:52 am I think you missed my post.

https://forum.rainmeter.net/viewtopic.php?p=199092#p199092
Hello, I saw your post. It just so happened after composing my reply to balala that i had to go for a trip away from home, therefore I currently have no access to my laptop now, and I was supposed to tell you but I forgot to do so. Sorry for that, and I'll get back to you as soon as I'm back from my trip. Cheers! :rosegift: