Macro and Loop

If you have created a unique MLServeCmd that performs a unique task, please post it here so others can learn from them.
bastoon
Newbie
Newbie
Posts: 2
Joined: Tue Dec 02, 2008 7:44 am
Contact:

Macro and Loop

Postby bastoon » Fri Dec 19, 2008 10:32 am

Hi
I am just a beginner I would like to know if I can do this kind of loop with a macro.
I would like to click on a button on ML and would like to set differents variables linked to this button.

In perl it should be like this

Code: Select all

for ($j=0 ; $j <7; $j++) {
   for ($i=0 ; $i <7; $i++){
         set_variable_web("mltv-canal-cc-prog-0~{{mltv-canal-c1-day-$j-prog-$i}}");
         set_variable_web("mltv-canal-cc-prog-0-start~{{mltv-canal-c1-day-$j-prog-$i-start}}");
         set_variable_web("mltv-canal-cc-prog-0-stop~{{mltv-canal-c1-day-$j-prog-$i-stop}}");
   }
}


where "set_variable_web" is the function to set the var in MLServer

So can I do with macro command ?
Thx for your help

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Postby CinemarDave » Fri Dec 19, 2008 11:54 am

You can do it with MLScript

Code: Select all

Option Explicit
Dim i
Dim j

For j = 0 to 6
    For i = 0 to 6
        MLServer.SetVariable "mltv-canal-cc-prog-0", MLServer.GetVariable(mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i))
        MLServer.SetVariable "mltv-canal-cc-prog-0-start", MLServer.GetVariable("mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i) & "-start")
        MLServer.setVariable "mltv-canal-cc-prog-0-stop", MLServer.GetVariable("mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i) & "-stop")
    Next
Next


Although it appears by running this script that all it will do is overwrite the three variables mltv-canal-cc-prog-0, mltv-canal-cc-prog-0-start and mltv-canal-cc-prog-0-stop 49 times. My Perl might be a little rusty. But you get the idea.

bastoon
Newbie
Newbie
Posts: 2
Joined: Tue Dec 02, 2008 7:44 am
Contact:

Postby bastoon » Fri Dec 19, 2008 1:12 pm

thx but you are right, correct syntax should be like this

Code: Select all

Option Explicit
Dim i
Dim j

For j = 0 to 6
    For i = 0 to 6
        MLServer.SetVariable "mltv-canal-cc-day-" & cstr(j) & "-prog-" & cstr(i) & ", MLServer.GetVariable(mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i))
        MLServer.SetVariable "mltv-canal-cc-day-" & cstr(j) & "-prog-" & cstr(i) & -start", MLServer.GetVariable("mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i) & "-start")
        MLServer.setVariable "mltv-canal-cc-day-" & cstr(j) & "-prog-" & cstr(i) & -stop", MLServer.GetVariable("mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i) & "-stop")
    Next
Next

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

MLScript For Dummies

Postby ronsatter » Wed Mar 25, 2009 11:27 pm

Calling all scripting pros:

I'm SCRIPT CHALLENGED so please forgive the dumb questions. I'm trying to understand this script example I found in this thread:

Code: Select all

Option Explicit
Dim i
Dim j

For j = 0 to 6
    For i = 0 to 6
        MLServer.SetVariable "mltv-canal-cc-day-" & cstr(j) & "-prog-" & cstr(i) & ", MLServer.GetVariable(mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i))
        MLServer.SetVariable "mltv-canal-cc-day-" & cstr(j) & "-prog-" & cstr(i) & -start", MLServer.GetVariable("mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i) & "-start")
        MLServer.setVariable "mltv-canal-cc-day-" & cstr(j) & "-prog-" & cstr(i) & -stop", MLServer.GetVariable("mltv-canal-c1-day-" & cstr(j) & "-prog-" & cstr(i) & "-stop")
    Next
Next


1. I can see that the script is looping through 3 variables and setting their values. I don't understand where the sources are. Do they already exist in ML as pre-defined variables?

2. Is this script cycling through a program schedule to set some start and stop times? ie, Day 1 Program 1, Day 1 Program 2 ... Day 6 Program 1, etc?

3. What are "cstr(i)" and "cstr(j)? (I see these often in scripts)

4. Does the first "Next" run the loop for the day number (j) and the final "Next" advance the loop for the program number (i)?

5. What does "Option Expicit" declare?

6. How do you save a script written in NotePad so that ML will recognize it?

7. If the script above were named "TV_Schedule", what would be the ML command syntax to execute it. Where would you store this script, and how does ML find it?


I know ... get a book! :lol: I'm asking on the forum because hopefully other script newbies like me can learn from your answers.

Would someone mind giving me a SIMPLE practical script example of how to loop through some items and populate variables?

Thanks,

Ron
If it ain't broke ... don't fix it!

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Postby ronsatter » Sun Mar 29, 2009 11:01 pm

Bump

Anyone?

Thanks,

Ron
If it ain't broke ... don't fix it!

User avatar
bhiga
Expert
Expert
Posts: 854
Joined: Tue Mar 08, 2005 10:28 pm
Location: San Jose, CA
Contact:

Re: MLScript For Dummies

Postby bhiga » Wed Apr 01, 2009 6:07 pm

Hey Ron

I'll answer what I know...

3. CStr converts the given parameter to a string. A value (number) becomes a string of the number. VBScript will generally convert types for you, but it's good practice to convert just to avoid stupid things.

4. Next completes the most-recent loop, so in this case the first Next is the end of the For i loop, which is also why the indentation matches. Proper indenting is good practice to show what matches what.

5. Option Explicit tells VBScript that variables must be declare (Var Foo) before they can be used. Without Option Explicity, variables can be created on-the-fly just be referencing them. While this sounds nice, in practice it becomes a real PITA because you when you type

Code: Select all

Foo = 1
Bar = 2
Result = Fooo + Bar
then Result is 2 and not the intended 3, because Fooo is undefined and therefore its value is zero (because Bar is a number, Fooo is used as a number).

With Option Explicit set, VBScript will error out and tell you Fooo isn't defined.

I don't use MLScript yet (and won't be able to for a while) so hopefully someone else will chime in on the other questions.
- Brandon
My MainLobby stuff (plug-ins, screenshots, etc)

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Postby ronsatter » Thu Apr 02, 2009 1:45 am

Thanks Brandon! I appreciate you taking time to teach us "Non-Scripters".

I actually understood your explanations ... now that's scarey! Next thing you know, I'll be writing my own MLStrings commands. :lol:

Now if someone else would be so kind to answer these remaining questions, I would be grateful.

6. How do you save a script written in NotePad so that ML will recognize it?

7. If the script were named "TV_Schedule", what would be the ML command syntax to execute it. Where would you store this script, and how does ML find it?


Thanks,

Ron
If it ain't broke ... don't fix it!

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Postby ronsatter » Sun Apr 12, 2009 10:53 pm

I'm bumping this thread in pursuit of answers to the remaining two questions.

ronsatter wrote:Now if someone else would be so kind to answer these remaining questions, I would be grateful.

6. How do you save a script written in NotePad so that ML will recognize it?

7. If the script were named "TV_Schedule", what would be the ML command syntax to execute it. Where would you store this script, and how does ML find it?


I think the answer to #6 is by saving the name of the file with the ".vb" extension. Is this correct?

As far as where to store scripts for use by MLScripts ... is there a special folder, ie, "Scripts" like there is in HS? If so, where should it be located?

And finally, what is the command syntax for MLScripts to run the script named "TV_Schedule"?

Thanks,

Ron
If it ain't broke ... don't fix it!

User avatar
CinemarDave
Site Admin
Site Admin
Posts: 10535
Joined: Fri Feb 07, 2003 8:56 am
Location: Planet Earth
Contact:

Postby CinemarDave » Sun Apr 12, 2009 11:11 pm

MLScripts has its own database for storing the scripts. They are not stored in external files. You can edit a script in an external edtitor but the last step will be to paste the script into the script editor window and save it.

If the script was named TV_Schedule then you would execute it by calling

MLScript|TV_Schedule

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Postby ronsatter » Mon Apr 13, 2009 1:35 pm

Thanks Dave
If it ain't broke ... don't fix it!

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Postby ronsatter » Thu Apr 23, 2009 10:30 pm

CinemarDave wrote:MLScripts has its own database for storing the scripts. They are not stored in external files. You can edit a script in an external edtitor but the last step will be to paste the script into the script editor window and save it.


Dave,

Please forgive me, but I still don't really understand how the MLScripts plugin processes a script it calls. Are you saying that the plugin makes a copy of the script it is calling, stores it in it's own database, and uses the database copy for future calls? What happens if the original script is modified? How does the plugin get the modified script?

I'm not getting it. After MLScripts saves a copy of the script, does it need the original script anymore? I see some vb scripts floating in the root folder of MLServer. Are those also copied to the database? Do they need to remain in there original location, so MLScripts can reference them through the file path?

Does everyone except me know the answers to these questions?

Oh the mystery of it all ... where's my blender?

Ron
If it ain't broke ... don't fix it!


Return to “MLServeCmd Examples”

Who is online

Users browsing this forum: No registered users and 1 guest