OptoScript is fun & easy


#1

There are many, many references to OptoScript here on the forums, and I’ve heard requests for “Advanced Training” on that topic.

To get the block rolling on this discussion, I’d like to share a fun little video discussing the many advantages and few disadvantages to using: [URL=“http://www.xtranormal.com/watch/12339834/two-action-blocks-ponder-their-fate”]OptoScript [click here].

Let me know what you think!

-OptoMary


#2

<facepalm>

Poor little guys… I’m glad that we still need them… They are too cute to not show up in any charts.

All jokes aside, for the longest time after OptoScript blocks were introduced I avoided them.
I think it was the strict syntax that put me off. I kept getting compile errors because I would have something backwards, or have left something out.
That and I did not use them often enough to remember how to ‘do’ things (like loops etc) in them.
To that end, when Opto gave us the sample chart with all those OptoScript examples, it made all the difference… You could just find and copy what you needed so fast, it made using them more of a viable option.

Like most things, if you don’t use it, you lose it… once you get over the first bit of bumpy road of getting used to using them the first time, it gets smoother and faster.
For those of us that have been programming Opto for eleventy eight years, we really had got fast using just the two blocks and feel (felt) that we really could do everything we needed with just those two little guys… why ‘complicate’ things with OptoScript?

Now that we have been using them for a while, they are part of the family, and we know their strengths and weaknesses and can use them where and when needed.
I know of at least one new to Opto programmer that [I]only[/I] programs in OptoScript. That’s all. Every chart, just OptoScript blocks.

I know that there is a bit of a wish list about OptoScript blocks been thrashed about on the forums, if you have any more of those ideas, please add them to that thread over there, the programmer knows about that one and has been thinking about them.

So for now, I would like to +1 Marys question and ask the same question…
If we were going to offer an advanced (or basic) topic on OptoScript, what would you like to see covered?
Now is your chance to shape the future of Opto 22 training.

Ben.


#3

Good points, Ben. I’d like the OptoScript editor to have a “spell check” button for comments, and a “fix all this code to do what I meant rather than what I coded” button. :slight_smile: Alas, our PAC Control wizard programmers are limited not only by practical restrictions, but also by the fact that the editor we use for OptoScript is a third-party package that Opto bought from another company (which hasn’t updated their code in a while). heavy sigh

In any case, we can’t do much about “other people’s code” but we can do something about our own! On this concept of “Every chart, just OptoScript blocks,” I say: “Don’t do it!” First of all, that’s not possible–quick, before looking at my answer for why, who can tell me the reason?

I’m sure Ben meant “…except the required Block 0” Action Block that I’m guessing our OptoScript-only friend leaves empty. I’m also guessing that our strictly-script friend uses more than one OptoScript block, at least? Because this is unappealing for multiple reasons:


I would not want to have to troubleshoot that block, especially if it has more than a page or two of script in it. (One rule of thumb for programmers is to break functions up into one- or two-pages or screen’s worth of code. If it’s more than that long, it’s hard to take in all at once and is probably missing an opportunity for modularizing further.)

Also, a flow chart (again, I’d want to keep it to about a page or screen’s worth) can help the next guy, even if it’s you, figure out at a glance what’s going on. Sometimes in our documents we call this “self documenting.” But what we really mean is, this visual description (as in, a flow-chart) is handy for understanding a process!

Here’s one I’ve been working on, which has plenty of OptoScript blocks in it (although the contents of each are not bigger than my screen):


Of course I could have used some if-then statements or a switch to replace those four condition blocks in an OptoScript block, but I like a “good-looking flow chart” (to quote my friend on the left in the little movie that started this thread). However, since I never write a perfect chart on the first try, I did have to do some troubleshooting. And when the part of the code that processes the users’ guess wasn’t working, it was easy for me to quickly set a breakpoint and narrow down my bug with it laid out like this.

Note: see the “delay” block in there, can’t emphasize the importance of that enough. Should be required somehow, just like Block 0. It’s always nice to put this where it’s clearly what all roads lead to, like I tried to do here. You can see at a glance that it will get hit every time through this main loop.

Also note the one block I DIDN’T use, and you’re unlikely to EVER see me use: the Continue block. If I were a fan of the Continue block, I might’ve put one just below that bottom “Loser?” Condition block instead of having my False arrow be so long. Why don’t I like it? Something against the lavender color? No.


For one thing, if you use a Condition block, you miss out on that visual clue I mentioned above, showing the looping clearly and that a delay is in there. Also, from when I first learned to program in BASIC back in 19-eighty-nevermind, the GOTO was a no-no. A Continue block seems like cheating/hacking to me. Like you’re magically being beamed up to some other location through a fictional teleporter.

But that’s just my unfair bias. I’m also not crazy about driving off-road in a four-wheel drive so what do I know? :wink:

Thoughts? Other preferences? Do share!

-OptoScripting-Mary


#4

Hi All,

Forgot to mention – the OptoScript Example strategy that Ben recommended has a new home as of the 9.1 release, as described in the release notes:
[INDENT]New PAC Project Examples Location
In order to be in compliance with Microsoft’s rules regarding directory structure, there is a new location on your hard drive for all of the examples that Opto 22 provides for PAC Project applications:
• For Windows 7 or Vista, go to[B]
C:\Users\Public\Public Documents\Opto 22\PAC Project 9.1

[/B]• For Windows XP, go to [B]C:\Documents and Settings\All Users\Shared
Documents\Opto 22\PAC Project 9.1[/B]
[/INDENT]
In general, if I’m not sure where I saved a strategy and don’t have it in my “recent files,” I’ve found that good ol’ DOS is the fastest at finding things for me. Here’s what I do:

  1. Open a command prompt (remember those? you can still get to one from windows by running “cmd” or searching help for “cmd” or “command prompt”)

  2. Change directories to the root of the drive to search by typing:
    cd \

  3. Do a directory listing using wildcard with a partial name (ending in .idb for a strategy), like this, where the /s option says: “look in all subfolders”
    [INDENT]C:&gt;[B]dir script.idb /s[/B]
    Volume in drive C has no label.
    Volume Serial Number is E8EF-BC4D

Directory of C:\Program Files (x86)\Opto22\PAC Project 9.0\Control Basic Examples\OptoScript Examples

06/14/2010 03:07 PM 36,715 OptoScript Examples.idb
1 File(s) 36,715 bytes

Directory of C:\Users\Public\Documents\Opto 22\PAC Project 9.1\Control Basic Examples\OptoScript Examples

06/14/2010 03:07 PM 36,715 OptoScript Examples.idb
1 File(s) 36,715 bytes

[/INDENT]Ta-da! Files found fast!
-OptoMary


#5

Speaking of flow charts and fun videos, someone told me about this flow chart and I just had to share, especially because Sheldon manged to create the dreaded “infinite loop” – something easy to do that must be avoided!

//youtu.be/Cj4OqNV59VY

-OptoMary