It is currently May 8th, 2024, 9:22 pm

Pullign random information from file?

Get help with creating, editing & fixing problems with skins
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Pullign random information from file?

Post by smurfier »

- Skin should be SKIN (line 16)

Yeah... that's what you get when you're editing your post while going out the door.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Pullign random information from file?

Post by poiru »

Here is a non-Lua solution that might work for you:

Code: Select all

[Variables]
Sat1=Saturday
Sat2=Caturday
Sun1=Sunday
Sun2=Funday
;etc..

[mDay]
Measure=Time
Format=%w

[mDayName]
Measure=Calc
Formula=mDay + (RANDOM ? 10 : 20)
UpdateRandom=0
LowBound=0
HighBound=1
Substitute="10":"#Sun1#","11":"#Mon1#","12":"#Tue1#","13":"#Wed1#","14":"#Thu1#","15":"#Fri1#","16":"#Sat1#","20":"#Sun2#","22":"#Mon2#","22":"#Tue2#","23":"#Wed2#","24":"#Thu2#","25":"#Fri2#","26":"#Sat2#"
(use MeasureName=mDayName on your STRING meter)
User avatar
Yggdrasil
Posts: 24
Joined: June 25th, 2011, 5:09 pm

Re: Pullign random information from file?

Post by Yggdrasil »

As I said, math.random() returns a random number in range [0,1], so for example: 0.0042876342, 0.98742873, 0.189742. If you want 0 or 1 randomly, you have to specify it as a parameter: math.random(0,1)
tostring is not required, Lua can concatenate strings with numbers.
Image
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Pullign random information from file?

Post by poiru »

smurfier wrote:The user is using a time measure to return the "Sunday" thru "Saturday" and another measure to return a random 1 or 0. The also have variables "Sunday1", "Sunday0" thru "Saturday1","Saturday0". We need to retrieve and return these variables. I used math.random() so as to eliminate the random measure. I'm wondering if I don't need to use tostring() on the random number before concatenating it.
Ah. You should use Day:GetStringValue() in that case (GetValue() will always return 0 when used with a Time measure returning a non-number [i.e a string]).
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Pullign random information from file?

Post by smurfier »

Yay! That gets it to work!

Code: Select all

PROPERTIES =
{
}

function Initialize()
   DayCheck = ""
   Rand = 0
   Day = SKIN:GetMeasure("MeasureToday")
end -- function Initialize

function Update()
   if DayCheck ~= Day:GetStringValue() then
   Rand = math.random(0,1)
   end
   DayCheck = Day:GetStringValue()
   A = SKIN:GetVariable(DayCheck..Rand)
   return A
end -- function Update
And my understanding has increased.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Versen
Posts: 8
Joined: July 22nd, 2011, 3:23 pm

Re: Pullign random information from file?

Post by Versen »

....Okay, I'm rather confused and conflicted on which would be a better choice. Just using RainMeter or "outsourcing" into Lua. I also think you all have my original idea in a charlie-foxtrot...

What i'm trying to do is call to variables placed inside of a Variables.inc file which is inside the same filepath as the "skin" itself. I'm doing this beacuse the original author has it setup this way, and i'm not wanting to deviate too much from that. From what i can tell the Lua script I'm given is more adept at that, and seems like it could allow for a larger file where i can store the messages I'm wanting to pull. But for simplicity's sake RainMeter seems like the better choice. Which leaves me at an impasse(for me).
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Pullign random information from file?

Post by smurfier »

Personally I like the lua approach better because it eliminates a measure (the one that generates a random number), it only generates a random number when the day changes, and you don't need to have a long substitute.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
Versen
Posts: 8
Joined: July 22nd, 2011, 3:23 pm

Re: Pullign random information from file?

Post by Versen »

Okay, so that shortens things some. But is there anyway to get to call to a file outside of the file the measure is placed in so I don't have to have a huge list of variables for that skin?

Edit. When replacing the lua script with the new one, I still get it returning 0. The String Meter I mean.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Pullign random information from file?

Post by smurfier »

I don't understand as my test skin has the variables in an .inc as well.
Here is my test "set" so that you can compare.

LuaTest.ini

Code: Select all

[Rainmeter]
Author=Smurfier
Update=1000

[Metadata]
Name=
Config=
Description=
Instructions=
Version=
Tags=
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
Variant=
Preview=

[Variables]
@include=Variables.inc

[MeasureToday]
Measure=Time
Format=%A

[MeasureLua]
Measure=Script
ScriptFile=LuaTest.lua

[Nil]
Meter=string
Text=""
Variables.inc

Code: Select all

[Variables]
Sunday0=Sunday0
Sunday1=Sunday1
Monday0=Monday0
Monday1=Monday1
Tuesday0=Tuesday0
Tuesday1=Tuesday1
Wednesday0=Wednesday0
Wednesday1=Wednesday1
Thursday0=Thursday0
Thursday1=Thursday1
Friday0=Friday0
Friday1=Friday1
Saturday0=Blah0
Saturday1=Blah1
LuaTest.lua

Code: Select all

PROPERTIES =
{
}

function Initialize()
   DayCheck = ""
   Rand = 0
   Day = SKIN:GetMeasure("MeasureToday")
end -- function Initialize

function Update()
   if DayCheck ~= Day:GetStringValue() then
   Rand = math.random(0,1)
   end
   DayCheck = Day:GetStringValue()
   A = SKIN:GetVariable(DayCheck..Rand)
   return A
end -- function Update
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Pullign random information from file?

Post by poiru »

smurfier wrote:I don't understand as my test skin has the variables in an .inc as well.
Here is my test "set" so that you can compare.
In this case, why not get rid of the Time measure (as suggested by Yggdrasil)?

Code: Select all

function Initialize()
	prevDay = ""
	retValue = ""
end

function Update()
	local currDay = os.date("%A")

	if currDay ~= prevDay then
		prevDay = currDay
		local randNum = math.random(0, 1)
		retValue = SKIN:GetVariable(currDay .. randNum)
	end

	return retValue 
end
(slightly optimized the code, too)