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
 
 

when I try to run the example code from the JavaScript manual. Chatscript blows up:

Javascript compiling: eval function fib(nif (== 0return 0if (== 1return 1return fib(n-1) + fib(n
-2); function test(ivar res []; for (05i++) { res.push(fib(i)); print(res.join(' ')); }
FATAL 56
uncaught error
PANIC 56
uncaught error (calling abort


I am running the latest version of CS.

Any Ideas?

Stephen G.

 

 
  [ # 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 ]

fib.js

// fib.js
function fib(n{
    
if (== 0return 0}
    
if (== 1return 1}
    
return fib(n-1) + fib(n-2);
}

function test(i{
     
var res [];
     for (
05i++) {
     res
.push(fib(i));
     
}
 console
.log(res.join(' '));
}

test
(4

console log output:

0 1 1 2 3

This test shows that the JavaScript include file in the CS manual runs (independent of ChatScript).  Hopefully this may help figure out what is going on.  Again, I was just making a joke in my first post, Stephen.

 

 

 
  [ # 5 ]

Hi Bruce

May I debug the JavaScript in your ChatScript manual? 

// fib.js updated
function fib(n{
    
if (== 0return 0}
    
if (== 1return 1}
    
return fib(n-1) + fib(n-2);
}

function test(j{
     
var res [];
     for (
0ji++) {
     res
.push(fib(i));
     
}
 console
.log(res.join(' '));
}

test
(8


“This will cause the JavaScript to be loaded and the JavaScript function test called with an integer value 4. This will, in turn, print out on the console 0 1 1 2 3”

No, actually the 5 in the for loop statement is what prints out: 0 1 1 2 3

Actually:  u: (test) ^testx(4)

would print out:  0 1 1 2

But the test function parameter (i) was not being used, so I changed it to (j) and used it in the for loop.

So for example: test(8)

Prints out: 0 1 1 2 3 5 8 13


Reference:

https://github.com/bwilcox-1234/ChatScript/blob/master/WIKI/ESOTERIC-CHATSCRIPT/ChatScript-Javascript.md

 

 
  [ # 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

 

 
  login or register to react