Extending new OnBeforeRuleFired function

Tips and questions about scripting your Verbot®.

Moderator: Staff

Extending new OnBeforeRuleFired function

Postby MikeA » Sat Nov 27, 2010 5:27 pm

Hi all

Been having a look at the new functions in VerbotStandard.vcm.

I've used the following code to determine what action led to the rule being fired (whether it was user input, send, startup or other). I think this works, but is not tested much. Not sure if other is useful (I have it there for testing).

This also requires additional functions in the vcm, as shown in the code below. The code goes in OnBeforeRuleFired function.

If there is a simpler way of doing it this, would be happy to know. Otherwise, hope this is useful.

Note: probably c# can use elseif. If so this code could be shorter.

Code: Select all
string inputvar = s.Vars["_input"].ToString();
string lastinputvar = s.Vars["_lastinput"].ToString();

if (lastinputvar == "")
   VerbotStandard.OnBeforeStartup();
else {
   if (inputvar == lastinputvar)
      VerbotStandard.OnBeforeSend();
   else {
      if (inputvar != "")
         VerbotStandard.OnBeforeUserInput();
      else
         VerbotStandard.OnBeforeOther();
   }
}
MikeA
MightyBot
MightyBot
 
Posts: 318
Joined: Sun Mar 22, 2009 1:35 pm

Postby JonC » Sun Nov 28, 2010 2:35 pm

I've clearly missed something, Mike.
What "new functions" are their in Verbot.Standard?
Can you point me to them?

btw, c# does not have an elseif construct, so your technique of
if (...) {...} else {if(....) etc is correct.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Postby Matt » Mon Nov 29, 2010 6:23 pm

JonC wrote:I've clearly missed something, Mike.
What "new functions" are their in Verbot.Standard?
Can you point me to them?

As of version 5.0.0.4 you can create a "VerbotStandard.vcm" file to attach to your knowledge bases which allow you to do powerful event based type code. You can download my sample files here, or read more about the new features in a post here: Verbot 5.0.0.4 Release Announcement

JonC wrote:btw, c# does not have an elseif construct, so your technique of
if (...) {...} else {if(....) etc is correct.


There is no "elseif" but you can do "else if(condition)"
Code: Select all
if(condition)
{

}
else if(condition)
{

}
else
{

}
Matt
OmnipotentBot
OmnipotentBot
 
Posts: 2079
Joined: Thu Feb 26, 2004 10:48 pm
Location: Calabasas, CA

Postby JonC » Mon Nov 29, 2010 8:27 pm

I think we're at cross purposes Matt.
I've got your download, but isn't Mike showing some other functions?
eg:
VerbotStandard.OnBeforeStartup()
VerbotStandard.OnBeforeSend()
VerbotStandard.OnBeforeOther()

What I'm really asking is can we write new functions for the Verbot.Standard vcm that also operate "globally"?
Or is the VerbotStandard.OnBefore... the global "hook" so to speak?
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Postby Matt » Mon Nov 29, 2010 8:37 pm

Sorry, I misunderstood, MikeA is using the built in Global hook function: OnBeforeRuleFired and making his own functions and calling them based on the state the verbot is currently in. This is a pretty clever trick, I'm glad you guys are experimenting with these new powerful scripting constructs!

-Matt
Matt
OmnipotentBot
OmnipotentBot
 
Posts: 2079
Joined: Thu Feb 26, 2004 10:48 pm
Location: Calabasas, CA

Postby JonC » Mon Nov 29, 2010 9:22 pm

Thanks Matt, I get it now - its only taken me three reads to work this out! :roll:
Mike's one clever guy with this!
I'm just kibbutzing over his shoulder, so to speak.
JonC
SupremeBot
SupremeBot
 
Posts: 665
Joined: Wed Apr 02, 2008 6:34 am
Location: Leicestershire, Great Britain

Postby MikeA » Tue Nov 30, 2010 12:25 pm

You're all too kind! I hope the trick works after that! :D

Yes, Matt summed it up well. Just shows how sometimes meaning is not so clear in forum posts.

The purpose behind this was because I thought it might be useful to know when the BeforeFired rule was after actual user input, or after a <send> (which would mean it could end up firing twice for the same input).
MikeA
MightyBot
MightyBot
 
Posts: 318
Joined: Sun Mar 22, 2009 1:35 pm

Postby leseur sylvain » Sat Apr 30, 2011 6:07 pm

Hi MikeA.
I understand how works VerbotStandardSample.vkb
and its VerbotStandandard.vcm...
A simple example of conversation is missing.
Theory is a thing, to apply it other one is...
Can you give us example on form of a little conversation using
your code in form of dialogue ?
What do you exactly want to do ?

Friendly
Sylvain.
leseur sylvain
OmnipotentBot
OmnipotentBot
 
Posts: 1677
Joined: Mon Nov 08, 2004 4:53 pm
Location: Suburb of Paris France


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests