AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

JavaScript example blows up
 
 
,`2p
 

 
  [ # 1 ]

That may be a good thing about ChatScript.
When JavaScript gets stuck, just blow it up!
( Just joking Stephen. )

 

 
  [ # 2 ]

How is the Fibonacci Sequence considered example code in ChatScript?

 

 
  [ # 3 ]

The code is straight from the javascript.md manual that Bruce wrote and is distributed with ChatScript.

I have other code that is much simpler but exhibits the same behavior.

outputmacro: ^jstestone(^arg1JavaScript permanent call void testPrint int eval

 function 
testPrint(n{
  
print("this blows up");
 
}

u
TEST_TWO (two)
## make call to javascript and output it.
calling with 42 \n ^flushoutput()
^
jstestone(42\n ^flushoutput()
back from calling with 42 
 

 
  [ # 4 ]
,`2`
 

 
  [ # 5 ]
,`2@
 

 
  [ # 6 ]

The problem isnt with the javascript, it is that the chatscriot engine crashes when the javascript is called.

Maybe it works on lunux but not windows.

 

 
  [ # 7 ]

crash in engine is failure when using eval instead of compile. You can temporarily use compile instead. I will fix the engine and release change in a bit

 

 
  [ # 8 ]

Thanks Bruce!!:-)

 

 
  [ # 9 ]

For those who may come after us.

here is code that works calling javascript.

Please note that this code unnecessarily makes repeated calls to ^jscodeset1
Bruce states that you really should just call this when the bot comes up but extra calls get ignored.

outputmacro: ^readjscodeset1() javascript permanent eval

 function 
testPrint() {
        
return("javascript working now!!")
 
}

outputmacro
: ^jstestprint() javascript permanent call string testPrint

topic
: ~test-javascript KEEP REPEAT (test javascript)

uTEST_ONE (one)
 ^
readjscodeset1()
 ^
jstestprint() 
 

 
  [ # 10 ]

oops,

Please note that this code unnecessarily makes repeated calls to ^jscodeset1

should read

Please note that this code unnecessarily makes repeated calls to ^readjscodeset1

 

 
  [ # 11 ]

>> Stephen Gissendaner: here is code that works calling javascript ...

Yes, it really works. Thanks!

However, I am trying to call JS function with argument{s}. For example, if function testPrint was ...

function testPrint(num) {
return("javascript working now. Argument is: " + num);
}

... how would output macro ^jstestprint look like ?

Supposing an int input-argument, I am trying with:
^jstestprintarg(^param_from_rule) javascript permanent call string testPrintArg(^param_from_rule) int

However, there is no matching!?

Could you please help?

 

 
  [ # 12 ]

I dont understand your code. you declare a javascript function trying to call a cs function?
And you say there is no pattern matching…. which means you have some input to match AND you have some rule that calls your javascript function, all of which are not shown

 

 
  [ # 13 ]

So outside of the JS definitions have the following line:

outputmacro: ^jstestprintarg(^param_from_arg) Javascript permanent call string testPrint int

This CS->JS mapping only needs to specify the name of the JS function, not the entire definition.

 

 
  [ # 14 ]

Unfortunately, it doesn’t work. (Neither Linux nor Windows.)

This is my *.top file:

outputmacro: ^readjscodeset() javascript permanent eval

function 
testPrint(num{
  
return("javascript working - arg is: " num);
}

outputmacro
: ^jstestprintarg(^param_from_rulejavascript permanent call string testPrint int

topic
: ~myjstest KEEP REPEAT []

t
Hi, try the JS test please !

uJSTEST (jstest _*1)
 ^
readjscodeset()
 ^
jstestprintarg(_0

On my side, if the input is jstest 8 the output will be: I don’t know what to say. It’s not (the expected): javascript working - arg is: 8

I still don’t know - how to invoke JS function with arguments?


p.s. Excuse me for wrong code in my previous post. Many attempts + wrong copy/paste = the wrong code. Sorry!

 

 
  [ # 15 ]

Everything looks OK, but I tend to use global variables in my JS function calls, so I would try that.
The interface from CS to JS seems to prefer variables that are passed by reference.

 

 1 2 > 
1 of 2
 
  login or register to react