Script Execution Order

Tips and questions about scripting your Verbot®.

Moderator: Staff

Script Execution Order

Postby MikeA » Sun Mar 14, 2010 1:56 pm

Quick question re. how scripting within Verbot executes.

Here's some example code:

Code: Select all
Your name: [name]
<?csharp vars["moreinfo"] = "y"; ?>
<send askmore>


Should it be linear, so will it execute in the order above, or does c# code execute first, or do sends get executed first, or Verbot code?

I've just encountered a problem that I'm trying to solve and maybe it is related to the above.

Thanks!
MikeA
MasterBot
MasterBot
 
Posts: 320
Joined: Sun Mar 22, 2009 1:35 pm

Postby JonC » Sun Mar 14, 2010 8:41 pm

That should execute sequentially, at least the c# and <send...> will.
If the Your name: [name] is an output, you might find that the c# executes before the text-to-speech engine does its job.
If that is the problem, the best solution is to write the whole thing in c#:
<?csharp Console.WriteLine("Your name "+vars["name"];
vars["moreinfo"] = "y"; Console.WriteLine("<send askmore>"); ?>

This will execute sequentially (I use this sort of thing a lot).
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Postby MikeA » Tue Mar 16, 2010 1:41 pm

Hi Jon

Done a few experiments with this. I think c# is executing completely before any outputs (whether from Verbot script or c#).

Using and adding to your code, as an example:

Code: Select all
<?csharp
Console.WriteLine("<send askmore>");
Console.WriteLine("Your name "+vars["name"];
vars["moreinfo"] = "y";
Console.WriteLine("<send askmore>");
?>


If askmore has the condition vars["moreinfo"] == "y", I'm pretty sure now that askmore would fire twice (because by the time either output is done, the c# code has already executed).

I think you were mostly right though, that this isn't I think about the c#, but that all outputs are done after the code execution.

So even with the outputs in c#, they would still fire at the end, using whatever is the last value of a variable in the code.
MikeA
MasterBot
MasterBot
 
Posts: 320
Joined: Sun Mar 22, 2009 1:35 pm

Postby JonC » Tue Mar 16, 2010 3:12 pm

Right, that wasn't quite what I meant...

If you only want to send to "askmore" if vars["moreinfo"] == "y", then the c# for this would be:
if (vars["moreinfo"] == "y") {Console.WriteLine("<send askmore>"); }
You could also have an optional else {} clause following the first set of {} as well in the c#.
(btw: note the double = (==) this is the c# equality, a single = is an assignment.)
As written, your code (above) does indeed have a double send and I am not sure what would happen in this case.
I do know that a Console.Write... statement (logically enough) doesn't stop the rest of the c# executing though.
I think that the net result would be as if the first <send..> statement were omitted, but I'm open to correction here.
However, if the next rule also involved c# or rule outputs that were dependant on the processing in the rule with the "double send", then the results could become unpredictable in that the first send could "take effect" before the previous rule finished processing (see below).
---
You wrote: I think c# is executing completely before any outputs (whether from Verbot script or c#).
That depends on exactly what you mean:
the c# itself will execute entirely sequentially (including Console.Write statements); however if you mean that the c# will (generally) have finished executing before the text-to-speech engine (or indeed the Verbot script tester) actually manages to "do its thing" and screenprint/say the outputs I concur.
This usually isn't a problem, unless you have a number of rule outputs (either Verbot script or c#) in a "cascade" of rules. [ie rules that send from one to the next.]
In this case, however, you can in fact "lose" parts of your script, at least within the Verbot player.
To obviate that I often choose to "assemble" my script in a vars-variable as the Verbot flows down the "cascade" and then output it all at once at the bottom of the "cascade".
[I use a dedicated vars-variable called "phrase". At the start of a cascade it is reset to an empty string (<?csharp vars["phrase"] = ""; ?>) or the first 'phrase' is used to overwrite any existing data (<mem.set phrase ...> in Verbot script or <?csharp vars["phrase"] = "..."; ?>). New info is most easily added in c# by <?csharp vars["phrase"] += " ..."; ?>
Then at the end of the cascade a single output (either [phrase] or our old friend Console.Write) outputs the lot. At this point the Verbot is expecting user input so timing becomes non-critical.]
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron