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..

Including ChatScript in another programming environment…
 
 

I am using a C based language for my current project and am trying get ChatScript working with it (but failing horribly). I have gone through the “ChatScript_External_Communications.pdf” many times but I don’t seem to understand how to do it correctly. If any more experienced ChatScript user could point me in the right direction it would be of great help.
The pdf seems quite short and to the point (only 3 pages long) but I can’t embed it into my own script editor (Lite-C).

The Chatscript manual states 3 basic steps for embedding:

STEP1. Edit “common.h” and compile the system

I open “src\common.h” in my script editor and uncomment the folowing lines:
// #define DISCARDSERVER 1
// #define DISCARDCLIENT 1
// #define DISCARDSCRIPTCOMPILER 1
// #define DISCARDTESTING 1
// #define NOMAIN 1

Then I execute “chatscript.exe” and type in my username and a couple commands like this:
Carlos
:build 0
:build Harry


STEP2. Invoke ChatScritp from your program

This step says to “call InitSystem()”
But how? Wouldn’t I have to include some “*.c” or “*.h” files first? Which should I include?

I tried including common.h like I do with other “external plugins” I use, like this:
#include “Plugins\ChatScript3.73\src\common.h”

But when I try to run my script it just throws this at me:
Error in ‘common.h’ line 39:
syntax error
<typedef unsigned long long int uint64;>

Is that the wrong file to include? Should I be doing something else that I am missing?

 

 
  [ # 1 ]

Step 2, augmented in next rev of doc…
To call these routines, your code will need a predeclaration of these routines. Just copy the routine declarations from ChatScript and put at the start of your file, e.g.,
unsigned int InitSystem(int argc, char * argv[],char* unchangedPath,char* readonlyPath, char* writablePath);
void InitStandalone();
void PerformChat(char* user, char* usee, char* incoming,char* ip,char* output);

You need to add all the CS .cpp files to your build list. Then you can compile your code along with ChatScripts.

 

 
  [ # 2 ]

Note—- the ChatScript code is “c++”.  It allows variables to be declared not at the start etc. So it won’t compile in a pure C compiler. You’d need a C++ compiler compiling your C code.

 

 
  [ # 3 ]

Thankyou very much for your help Bruce. That would be problem but mabe I could just throw in a file before it with all the declares and function prototypes. I must admit I don’t use c++ so I’m not sure what other problems I could have. Are there any other major incompatibilities between the two?

There is one major problem for me though, the engine I am using does not support these types of 64bit variables…
From a conversation with the Lite-C dev:

...implementation in Lite-C and for this I need an unsigned 64 bit integer, but it looks like Lite-C doesn’t have one? I tried the usual typedef unsigned long long uint64_t stuff separately for testing, but the compiler complains about it. Do I have any options beside implementing my own integer math framework…

lite-C has no 64 bit integer, so you must implement it yourself, but the compiler supports 64 bit data through the double variable. So you already have the 64 bit variable handling, you only need to provide the integer arithmetic.

I did a search on all the files and found 6 of these 64b typedefs, then did a search for those and… well I have a big problem.

I was wondering if there was a version of ChatScript that did not use them? Mabe an old version?

Other than that the only quick solution I can think of is running them separately and communicating externally, but I would prefer not to if there is any other possibility.

 

 
  [ # 4 ]

You could switch to a different compiler.  A C++ compiler can also compile .c files. Msoft has Visual Studio C++ Express for free.

Otherwise I don’t have much useful to say. The basic numeric system in CS is all 64 bit (these days the main servers are 64bit) as is its handling of dictionary data bits.

 

 
  [ # 5 ]

Thankyou for your suggestions. I have been looking into several options but unfortunately none seem apealing so far.

Using a different compiler is going to a challenge (if even possible) as my code is pretty much engine bound (as is my current compiler) with many engine specific functionality, variables, etc. There is just too much extra non-standard stuff. Switching to a different environment would mean scrapping alot of work (and time) so I am pretty much stuck with I am using so far. Modifying chatscritp would also be just to much work for me at the moment that I can’t fit into my schedule. I have also looked at several C++ to C compilers but even though it would be the best approach so far it would leave me with unreadeable/unmodifyable/unmaintainable code and I would still have the 64b problem to deal with.

For now I will continue working the other aspects of my project. Until I either come up with a better aproach to solve this problem, or just learn from chatscript to improve my rudimentary attempt at nlp with whatever I can learn to at least get it to an “acceptable” level. I would love to use this impressive tool and I havn’t given up yet, but for now I just don’t have time for the possible solutions.

 

 
  [ # 6 ]

This is just off the top of my head here, but what if the ChatScript engine were compiled into a DLL, rather than as a stand-alone program, and it was then called via certain hooks? I’ve seen many a Windows program (can’t help with Linux programs here, as I have no experience at the coding level with that OS branch) that are written in one language and use DLL’s that are written in another. Might this not be worth exploring? smile

 

 
  [ # 7 ]

Is this for windows or Linux?

I’m not sure what this means: Using a different compiler is going to a challenge (if even possible) as my code is pretty much engine bound (as is my current compiler) with many engine specific functionality, variables, etc.

What does “engine” refer to.

 

 
  [ # 8 ]

Sorry, I didn’t notice I have not mentioned that in this thread Bruce. In my spare time I am a hobbyist game programmer and around a year ago I decided to have a go at something a little more serious than my past hobby projects. I purchased a commercial license for Conitec’s A8 engine that uses their “Lite-C” language that limits me to their compiler. It basically combines C, HLSL, and a better version of their previous c-script language. It utilizes all their A8 engine functionality, and provides a ton of usefull in-built functions, structs, and variables for managing all the 3d rendering, collision detection, animation, mesh manipulation, multimedia, etc… and a lot of functions to simplify all that stuff and common 3d math used for videogames. It is very usefull for someone like me (or small teams) as it speeds up alot of the tedious process behind managing all that, but makes my code dependant on their Lite-C compiler.

That sounds like a great idea Dave, all of the other “external plugins” I use to enhance Lite-C’s functionality (LBGUI for the interface, ANet for multiplayer and Voip, and a SQLite plugin) work like that. All I do to use them is dump a DLL and a “.h” file in the project folder, and include the .h that contains whatever function prototypes it needs in my code and it’s ready to go. Unfortunately I have never compiled a DLL myself and have no idea what that involves, that is probably why I didn’t even think of that approach. The plugins I currently use came “as is” and provided both the dll and .h for me, but it is definately worth lookng into.

Just a shot in the dark here but… Would you happen to have already done this before and have a DLL for ChatScript? (No worries about Linux, I use Windows myself)

 

 
  [ # 9 ]

Sadly, I haven’t, no. I’ve written a few programs in different versions of Visual Basic, from VB6 to .net, but I’ve never needed to write anything as a DLL. I know it can be done (the documentation says so), but I haven’t the first clue as to how it’s done.

 

 
  [ # 10 ]

I can probably figure it out and make chatscript into a DLL.  I’ll get back to you in a few days.

 

 
  [ # 11 ]

Wow thanks Bruce!

 

 
  [ # 12 ]

OK.  Having played with the issues, we have to decide what you really need.  A DLL is a dynamically loaded library, but I don’t see any reason you shouldn’t just include a regular static library (since you always need it).  I have built a project which generates a chatscript library and have a header file one can include for the two functions you need of it.  I could email them to you to see if they work for you (email my gmail account your email).  Currently they are built with some std DLL’s that have to load from visual studio.  If they are not on your machine, maybe I’ll need to send you those as well.  I tried to statically link them in, but then my test program also built in visual studio had lots of duplicate linker symbol complaints. I can also try sending it to you, since you are using the lib in a non studio program, maybe there will be no issue… Basic point is we need to experiment to get you what you need.

 

 
  [ # 13 ]

Thankyou very much Bruce for the work you are putting into this for me! I would love to test that approach. Would the two functions be InitSystem() and PerformChat()? I am sending you my email right now.

 

 
  [ # 14 ]

I am taking a closer look at InitSystem and wondering if the arguments for filepaths are absolute or relative to the chatscript folder (or will be relative to where I place the header and library).

Lets say I have a main folder called “MyProgram”, this folder is located inside “D:\projects”
Inside that “D:\projects\MyProgram” folder I would have the library file and another subfolder called “Plugins”
All the chatscript files and folders are inside “D:\projects\MyProgram\Plugins\ChatScript\” conserving the original file structure as they are now

How would I call InitSystem?

With absolute paths?
InitSystem(0, NULL, “D:\projects\MyProgram\Plugins\ChatScript\DICT”, “D:\projects\MyProgram\Plugins\ChatScript\TOPIC”, “D:\projects\MyProgram\Plugins\ChatScript\USERS”);

With file paths relative to the library? (In this example the library is placed inside “D:\projects\MyProgram”
InitSystem(0, NULL, “Plugins\ChatScript\DICT”, “Plugins\ChatScript\TOPIC”, “Plugins\ChatScript\USERS”);

Or relative to the chatscript file folder?:
InitSystem(0, NULL, “DICT”, “TOPIC”, “USERS”);


A couple of other questions I have about InitSystem is if it takes double “\” or simple “\” filepaths, and if 0/NULL are valid for argc/argv?

 

 
  [ # 15 ]

for now, let’s just do basic chatscript. the paths should all be null, defaulting everything to the file structure that CS normally uses. if argc is 0 then argv can be null

 

 1 2 3 > 
1 of 3
 
  login or register to react