Load variables from a text file

Tell others how you're using MainLobby.
User avatar
gregoryx
Simply Incredible
Simply Incredible
Posts: 6599
Joined: Tue Sep 30, 2003 10:15 pm
Location: Newport Beach, CA
Contact:

Load variables from a text file

Postby gregoryx » Sat Sep 10, 2005 6:05 pm

In the interest of making it even faster and easier for me to build dynamic scenes and menus and track what state a given client is in and what scene and zone they're in, I'm finding more and more reliance on BIG lists of variable values that need to be set.

To me, editing these SetVariable things in a command map is a tedious pain. I use a text file, then just paste them into the command map builder and hit "save".

I thought I'd save a step by making MLServer build the variables directly from a text file, so I could just have a list of variables that I want set and the values to set them to and it would do it - no matter how long the list - and I could just change a line or add more at will and it would be as simple as hitting a button to reload them all.

That is what this is about.

There are two possible actual methods posted here. One is rather strict on the Text to Variables file format. It must not contain blank lines or extraneous text or such. It's faster as it has less lines of code to process the text file.

The second method allows blank lines and REMark lines (anything starting with a "REM" is ignored). This version is twice as many commands per text-to-variable element and takes as much longer to run.

Thanks to Brandon, Bob, Dave, and the rest of the Cinemar crew that made all the pieces possible.

The text below is also contained in this file on my site.
GOAL:
---------------------------------------------------------------------------
Use text file(s) to load variable names and values


METHOD:
---------------------------------------------------------------------------
Put variable names and values in simple text file with a "one variable and value per line" format.
Build a command map to set a few "base variables", including the location of the text file.
Launch the extraction / creation process from the last line of the above command map.


FORMAT:
---------------------------------------------------------------------------
One line per variable and variable value.
LIMIT of 45 lines in the text file.
This method WILL NOT read more than 45 lines in the text file.


FUTURE PLAN:
---------------------------------------------------------------------------
Include a method to break files more than 45 lines into multiple 45-or-less files.
This will make the input file length unlimited.


REQUIRED PLUGINS (in alphabetical order so you can scroll for them):
---------------------------------------------------------------------------
MLConditional
MLMath
RunCmdMap
SetVariable
wscReadFileEx
wscVBSEvaluate
wscStringFunctions


PROCESS FLOW (IfThen method):
---------------------------------------------------------------------------
- Determine number of lines in a file
- Read the value of each line
- If the value of the line is empty or starts with "REM", ignore it
- Split the line into the two components based on a user-determined separator (semi-colon intially)
- Create the variable and the content from the two components
- Loop for number of lines in file
- Exit out after 45 lines and MLServer bombs after that - unknown why


CODE TO RUN:
---------------------------------------------------------------------------
Set.TextToVarStart.BaseVars
Note that the name of this command map doesn't matter.
It can be anything as long as it contains relevant commands.
Set.TextToVarLoop
Set.TextToVarLoopCheck


Set.TextToVarStart.BaseVars:
Note that the name of this command map doesn't matter.
It can be anything as long as it contains relevant commands
and calls the Set.TextToVarLoopCheck as the last line.
=====================================================================
MLServeCmd.SetVariable|TextToVarInputFile~c:\program files\mlserver\data\vars.txt
MLServeCmd.SetVariable|TextToVarDelimiter~;
MLServeCmd.SetVariable|TextToVarCurLineNum~1
MLServeCmd.wscReadFileEx|>NUMLINES>TextToVarTotalLineCount>{{TextToVarInputFile}}
MLServeCmd.RunCmdMap|Set.TextToVarLoopCheck


Set.TextToVarLoopCheck:
=======================
MLServeCmd.wscVBSEvaluate|{{TextToVarCurLineNum}}>{{TextToVarTotalLineCount}}~TextToVarComplete
MLServeCmd.wscVBSEvaluate|{{TextToVarCurLineNum}}>45~TextToVarComplete
MLServeCmd.MLConditional|IsEqual##{{TextToVarComplete}}##True####RunCmdMap|Set.TextToVarLoop


Set.TextToVarLoop (no blank line or REMark checking):
=============================================
MLServeCmd.wscReadFileEx|>READLINE>TextToVarTemp0>{{TextToVarInputFile}}>{{TextToVarCurLineNum}}

MLServeCmd.wscStringFunctions|EXTRACT~TextToVarTemp1~{{TextToVarTemp0}}~{{TextToVarDelimiter}}~1
MLServeCmd.wscStringFunctions|EXTRACT~TextToVarTemp2~{{TextToVarTemp0}}~{{TextToVarDelimiter}}~2
MLServeCmd.SetVariable|{{TextToVarTemp1}}~{{TextToVarTemp2}}

MLServeCmd.MLMath|ADD~TextToVarCurLineNum~{{TextToVarCurLineNum}}~1
MLServeCmd.RunCmdMap|Set.TextToVarLoopCheck


Set.TextToVarLoop (with blank line and REMark checking - allowing easier reading):
==================================================================================
MLServeCmd.SetVariable|TextToVarSkip~0
MLServeCmd.wscReadFileEx|>READLINE>TextToVarTemp0>{{TextToVarInputFile}}>{{TextToVarCurLineNum}}

MLServeCmd.wscStringFunctions|LEN~TextToVarTemp0Len~{{TextToVarTemp0}}
MLServecmd.wscVBSEvaluate|{{TextToVarTemp0Len}}<4~TextToVarEmpty
MLServecmd.MLConditional|IsEqual##{{TextToVarEmpty}}##True##SetVariable|TextToVarSkip~1##

MLServeCmd.wscStringFunctions|LEFT~TextToVarTemp0Left1~{{TextToVarTemp0}}~3
MLServecmd.MLConditional|IsEqual##{{TextToVarTemp0Left1}}##REM##SetVariable|TextToVarSkip~1##


MLServecmd.MLConditional|IsEqual##{{TextToVarSkip}}##0##wscStringFunctions|EXTRACT~TextToVarTemp1~{{TextToVarTemp0}}~{{TextToVarDelimiter}}~1##
MLServecmd.MLConditional|IsEqual##{{TextToVarSkip}}##0##wscStringFunctions|EXTRACT~TextToVarTemp2~{{TextToVarTemp0}}~{{TextToVarDelimiter}}~2##
MLServecmd.MLConditional|IsEqual##{{TextToVarSkip}}##0##SetVariable|{{TextToVarTemp1}}~{{TextToVarTemp2}}##

MLServeCmd.MLMath|ADD~TextToVarCurLineNum~{{TextToVarCurLineNum}}~1
MLServeCmd.RunCmdMap|Set.TextToVarLoopCheck



FORMAT OF TEXT FILE:
---------------------------------------------------------------------------
Var1Name;Variable value to set for variable one
Var2Name;This is the value that will be set for variable two


Sample of my menus being set this way:
---------------------------------------------------------------------------
REM This is for the base menu values

MenuBase01.00Label;MAIN MENU
MenuBase01.00Cmd;Menu.Set.Main2
MenuBase01.00aLabel;MAIN MENU (1 of 2)
MenuBase01.00bLabel;1 of 2
MenuBase01.00bCmd;Menu.Set.Main2
MenuBase01.01Label;CD Music
MenuBase01.01Cmd;Client.Scene.Overlay.MusicLobby
MenuBase01.02Label;XM Radio
MenuBase01.02Cmd;Client.Scene.Overlay.XMLobby
MenuBase01.03Label;DVD Movies
MenuBase01.03Cmd;Client.Scene.Overlay.DVDLobby
MenuBase01.04Label;A/V Controls
MenuBase01.04Cmd;Client.Scene.Overlay.AVControl
MenuBase01.05Label;Cameras
MenuBase01.05Cmd;Client.Scene.Overlay.Cameras
MenuBase01.06Label;Weather
MenuBase01.06Cmd;Client.Scene.Overlay.WeatherLobby
MenuBase01.07Label;Slide Show
MenuBase01.07Cmd;Client.Scene.Overlay.SlideShow
MenuBase01.08Label;Photo Album
MenuBase01.08Cmd;Client.Scene.Overlay.PhotoAlbum
MenuBase01.09Label;Lighting
MenuBase01.09Cmd;Client.Scene.Overlay.Lighting
MenuBase01.10Label;Status View
MenuBase01.10Cmd;Client.Scene.Overlay.Status1
MenuBase01.11Label;Recent Callers
MenuBase01.11Cmd;MLCallerID|GET
MenuBase01.12Label;...more...
MenuBase01.12Cmd;Menu.Set.Main2

REM END

Billmans
Newbie
Newbie
Posts: 11
Joined: Wed Sep 21, 2005 11:10 am
Contact:

Postby Billmans » Thu Sep 22, 2005 8:48 am

gregoryx,

Trying to understand how you built your ML.

I am new at this and have a couple of questions.

1. What .mls file to you load first, Kstartup.mls ???
2. I am trying to install all the plugins that you talk about in this post, but I am unable to find,

RunCmdMap
SetVariable

wscVBSEvaluate

And I couldn't find
wscStringFunctions
but I found
wscStringFunctionsEx

Also, am I too understand that you also have batch files and scripts on your computer that are run on startup?

Sorry if this sounds stupid, but I am trying to wrap my head around this.

Thanks for you help,

PS, your designs and functionality look great,.... I would like a similar setup with multiple zones, and two, mabee three touchpanel controll screens.

Thanks

User avatar
mosleyh
Intermediate
Intermediate
Posts: 413
Joined: Tue Jul 12, 2005 11:55 am
Location: Charlotte, NC
Contact:

Postby mosleyh » Thu Sep 22, 2005 10:34 am

Until Gregoryx has time to respond, here's the source for

wscVBSEvaluate
wscStringFunctions


http://www.cinemaronlineforums.com/forum/viewtopic.php?t=5114


RunCmdMap is in this thread:

http://www.cinemaronlineforums.com/forum/viewtopic.php?t=4583&highlight=runcmdmap

SetVariable is a part of MLServer and doesn't require a separate plug in.

It's explained in the cheat sheet here (if you don't already have it):

http://www.cinemaronlineforums.com/forum/viewtopic.php?t=1434

When you use the Search function in the forum, try switching the results to posts, in my experience it helps when you're looking for something specific like a plugin.

hope that helps. . . :)

User avatar
gregoryx
Simply Incredible
Simply Incredible
Posts: 6599
Joined: Tue Sep 30, 2003 10:15 pm
Location: Newport Beach, CA
Contact:

Postby gregoryx » Thu Sep 22, 2005 10:15 pm

Thanks, mosleyh!

Let's see... anything to add...

Yes, kStartup.mls was (and sometimes still is) used as the initial load scene on the clients. The advantage to this is that it calls a different "startup" command (or can call a different startup command) per client, allowing them to do different things based on server configs, not based on anything changed or configured on the client itself.

For example, I return them to the last scene that client was "active" on when they restart. Sometimes, I'll use it to tell them to download new files since I've done updates. Things like that.

The batch files and/or scripts that I have used are mostly moved over into MLServer command maps now; there are a couple of "update client" things that use batch files, but that's about it.

It looks like mosleyh got you pointed in the right direction for all the plugins. Thanks, mosleyh.

Welcome aboard!
:D


Return to “How are you using MainLobby?”

Who is online

Users browsing this forum: No registered users and 1 guest