I have debugged the code and found the w of MeterString had the right value I want, but somehow a part of it missed.
```ini
Code:
[Rainmeter]Update = #Update#; Variables option is to define variables[Variables]; all time variable's unit is millisecondUpdate = 100RefreshTime = 300*1000Scale = 1[Script]Measure = ScriptScriptFile = text.lua; define a kind of style for the text[TextStyle]; family name of the font to be used in the skinFontFace = 宋体FontColor = 255, 255, 255, 255; you could categorize sections by group, it will make it convenient to put bang into; multiple sections. It means you only to invoke a bang with parameter, whose type is group,; to achive it.Group = StringGroupStringEffect = Shadow; determine the background color of the text, and (0, 0, 0, 1) has a benefit when you execute; mouse actions while the background color is virtually transparentSolidColor = 0, 0, 0, 1AntiAlias = 1; the main part of a motto[MeterString]DynamicVariables = 1Meter = String; you can regard measure section as a function and it will return a string value; [] denotes a bang which is a kind of function represented by section; & denotes the section is a customized section but a built-in sectionText = " [&Script:GetText()]"; a meter has different types, and a type of meter has different styles; however, the MeterStyle is customizable, and it is represented by a sectionMeterStyle = TextStyleFontSize = 17*#Scale#; to decide the position of the meterX = 0LW = [&Script:Calc()]clipString = 2LeftMouseUpAction = !CommandMeasure Script "MyUpdate()"; the secondary of a motto[MeterSecondaryString]DynamicVariables = 1Meter = StringText = [&Script:GetSecondaryText()]FontSize = (14*#Scale#)MeterStyle = TextStyleX = (-25*#Scale#)R; Y = (-15*#Scale#)RY = [MeterString:H]H = 30*#Scale#clipString = 2LeftMouseUpAction = !CommandMeasure Script "MyUpdate()"```
Code:
function GetText() return JSON[ID].Textendfunction GetSecondaryText() return JSON[ID].SecondaryTextendMyUpdate = function() ID = math.random(1, #JSON)endfunction Initialize()-- *** retrieve the content of a file *** -- io is a class in lua and read funtion in it creats a instance as return value local relativePath = "motto.json" -- io.open could not directly resolve to relative path and you have use -- SKIN:MakePathAbsolute to convert the relative to the absolute. -- through colon we can infer that SKIN is an object and the object has to be a parameter -- in the function and the SKIN is an unique object representing current skin local absolutePath = SKIN:MakePathAbsolute(relativePath) local file = io.open(absolutePath, "r") if file then -- if you need to have a object parameter, then use colon -- if you need not to have a object parameter, then use dot -- string "*a" is a kind of control parameters and means to -- read whole content of the file -- beaware that a local variable has its scope limited to the -- block where it is declared. a block is the body of a control structure Content = file:read("*a") -- like c++, a opened file needs closing after using file:close() -- the second parameter's type is number and means the error's level -- if it is 2, the error output will include the number column where -- the error occurs. else error("The file doesn't exits.", 2) end-- *** parse the content of json *** -- dofile is to include external library or lua snippet into the current script -- GetVariable is a function of skin aiming to retrieve variables in the skin -- @ represents the directory of current skin resource folder -- the return value is an object indicating a lua file cjson = dofile(SKIN:GetVariable("@")..'Script\\json.lua') -- decode is a function in the json.lua file JSON = cjson.decode(Content)-- *** Initialize which motto is chosen *** -- math is a object and you do not need to use data in math object so ID = math.random(1, #JSON)endfunction Min(a, b) return a < b and a or bendfunction Calc() local length = #JSON[ID].Text -- like document in javascript local scale = SKIN:GetVariable("Scale") local result = Min(700, 15*scale*length) print(result) return resultend ```
Statistics: Posted by zIa1yBX5 — Yesterday, 4:23 pm