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

Starting out basic before trying with my own program this is what I have done so far.

-Unzipped a fresh ChatScript folder.

-Executed chatscript.exe
-Entered the username “Carlos”
-Entered “:Build 0”
-Entered “:Build Harry” (1 spelling warnings, 0 more serious warnings)
-Closed chatscript.exe

-Placed the “ChatScript.lib” and “lib.h” files you sent me into the main chatscript folder (same place where chatscript.exe is located)

-Created a new test project in Lite-C (in the main chatscript folder) called “testing.c”

The contets of “testing.c” is just the very basic as follows:

#include <acknex.h>
#include "lib.h"

void main()
{
 fps_max
=60;
 
level_load(NULL);
 
 
InitSystem(NULL,NULL,NULL,NULL,NULL);
 
 while(
1)
 {
  wait
(1);
 
}

When I try to run “testing.c” in Lite-C it throws this at me:

Compiling TESTING.C - [Esc] to abort..
Error in ’ ‘lib.h’ line 1:
syntax error
< extern “C” unsigned int InitSystem(int argc, char * argv[],char* unchangedPath = NULL,char* readonlyPath = NULL, char* writablePath = NULL);
>
.. 0.038 sec
Error compiling TESTING.C

I tried commenting that line in lib.h just to see if it had anything to do with argv or the “=NULL” after each parameter since in Lite-C I never use argv or an assignment in function parameters. The second line gives me the same result.

I tried just the functions as if they were not extrenals to test if Lite-C would accept them

#include <acknex.h>
//#include "lib.h"

unsigned int InitSystem(int argcchar argv[],charunchangedPath NULL,charreadonlyPath NULLcharwritablePath NULL)
{
   
}

void PerformChat
(charusercharuseecharincoming,charip,charoutput)
{
   
}

void main
()
{
 fps_max
=60;
 
level_load(NULL);
 
 
//InitSystem(NULL,NULL,NULL,NULL,NULL);
 
 
while(1)
 {
  wait
(1);
 
}

I get the same:

Error in ‘line 4:
syntax error
< unsigned int InitSystem(int argc, char * argv[],char* unchangedPath = NULL,char* readonlyPath = NULL, char* writablePath = NULL)
>

I tried only with the second function:

#include <acknex.h>
//#include "lib.h"

void PerformChat(charusercharuseecharincoming,charip,charoutput)
{
   
}

void main
()
{
 fps_max
=60;
 
level_load(NULL);
 
 
//InitSystem(NULL,NULL,NULL,NULL,NULL);
 
 
while(1)
 {
  wait
(1);
 
}

and this runs just fine…

So I am guessing it dosnt like extern “C” and something else specific in the InitSystem function prototype

I tried different variations InitSystem to test, removing only the “=NULL” after the parameters, removing only the “char * argv[]”, and removing both.
It only works when removing both.
This runs perfectly withought any errors:

unsigned int InitSystem(int argc,charunchangedPath,charreadonlyPathcharwritablePath)
{
   
}

void PerformChat
(charusercharuseecharincoming,charip,charoutput)
{
   
}

void main
()
{
 fps_max
=60;
 
level_load(NULL);
 
 
//InitSystem(NULL,NULL,NULL,NULL,NULL);
 
 
while(1)
 {
  wait
(1);
 
}

So I am pretty sure the problem with the function protype is that Lite-C does not like it if I try to assign something in the parameters themselves, and also does not like the “char * argv[]”.
Besides that, regarding the header file I think Lite-C also has a problem with: extern “C”

I am thinking mabe a solution to the function parameters themselves could be an extra function in the ChatScript.lib itself? Some function as an “in-between step” for me to call in Lite-C with only the last 3 parameters? something that would automatically pass the argv with whatever default values it would need to work… like this mabe:

unsigned int InitSystem_LC(charunchangedPath,charreadonlyPathcharwritablePath)
{
     int argc 
whatever?;
     
char argv[] whatever?;
     
unsigned int result;

     
result InitSystem(argc,argv[],unchangedPath,readonlyPath,writablePath);
     return(
result);

That way the header would use this InitSystem_LC function and internally in the lib it would call the InitSystem function.

 

 
  [ # 17 ]

I think I may have found the problem with “extern C” in the Lite-C Manual

Using the DLL in C-Script and lite-C
Ready? Now compile your DLL - let’s assume that you named it plugin.dll - and copy it either into your acknex_plugins folder if you want to use it in many projects, or into the work folder if you only want to use it in a certain project . How can we now call our ldexpc function by a script? We have to declare the function prototype in the script, or in a script header file. In lite-C it’s just a normal prototype (and you can use other variable types than var), in C-Script we need a special dllfunction declaration:

dllfunction ldexpc(x,n); // declaration of a DLL function in C-Script
function ldexpc(x,n);  // declaration of a DLL function in lite-C

It seems like the problem is just to substitute “extern C” with “function” because lite-c does extern c by itself already?

 

 
  [ # 18 ]

There are two issues probably because my header file is compliant to C++ and not C..

1 extern “C” is a C++ concept. Since yours is not a C++ compiler, you can remove it from the function declaration entirely in lib.h
2. Probably C doesn’t accept default arguments in a specification. Change xxx = NULL to remove the = NULL for the 3 char*‘s.

Then probably it will compile.

 

 
  [ # 19 ]

Thankyou very much for the new file. I am still having one last issue though with “char * argv[]”
I assume it is an array of strings (of variable amount of strings) in C++?
I don’t think that is possible as a parameter in a function nor as a declaration in C. Arrays either have to be declared with a fixed length, or a dynamic array can be created at runtime but with malloc.

Either it is declared with a fixed number of fields
char* argv[3];

Or if it is a dynamic array it has to allocated at runtime with malloc (and each time it changes size it has to be re-allocated again)
char* argv;
argv* =malloc(3*sizeof(char*));

Not even a varialble works
int x;
char* argv[x];
the above declaration does not work in C either unless x is a constant.
#define x 3
char* argv[x];

Also as a parameter I cannot pass an array to a function in C. Each pointer of the array would have to be a separate parameter in the call, or a pointer to the whole structure could be a parameter. But never an array of pointers as a single parameter.
I am only one parameter away, so close to being able to use chatscript!

 

 
  [ # 20 ]

This is supposed to be legal c:

main(int argc, char** argv)
{
int i;

printf("argc = %d\n", argc);

for (i = 0; i < argc; i++)
printf("argv[%d] = \"%s\"\n", i, argv);
}

So you should be able call InitSystem if you rewrite the hearder to char**
But if your C is non-standard and does not allow arrays to be passed, assuming you are building on a 32-bit system so that pointers are 32 bits, you can just define the function as:
void InitSystem(int,int,int,int,int)  and pass in 0’s

 

 
  [ # 21 ]

Yes sorry, it has been a long time since I used dynamic arrays.
Even the example for allocating dynamically with malloc I wrote above was wrong, it’s supposed to look this:
char* argv;
argv = (char*)malloc(3*sizeof(char));

Anyway back to the header, I just tested it with **argv and it does work fine in Lite-C. The program compiles fine with the header included. But when I then try to call the functions in my code I get the following:

Error E1512 Empty function called in main

That usually happens to me when I declare a function prototype and mispell the original function’s name. And then later in my code I use the prototype that does not actually have a real function equivalent (I hope that sentece made sence). So I think the prototype is not linking correctly into the lib file mabe? Like if it dosn’t recognize its equivalent in there?

This is my current “testing.c” file:

#include <acknex.h>
#include "clib.h"

STRINGchatscript_answer;

void main()
{
 fps_max
=60;
 
level_load(NULL);
 
 
InitSystem(0,NULL,NULL,NULL,NULL);
 
 
chatscript_answer=str_create("test");
 
PerformChat("Carlos","Harry""Hello",NULL,chatscript_answer);
 
 while(
1)
 {
  wait
(1);
 
}

And this is my current clib.h file:

unsigned int InitSystem(int argcchar** argv,charunchangedPathL,charreadonlyPathcharwritablePath);
void PerformChat(charusercharuseecharincoming,charip,charoutput)

I have no idea where to go from here… Mabe I need to put something else in the header so it knows what lib file to look in? Or mabe the char** makes it think the other function is different because it’s parameters are not exactly the same?

If I comment out my InitSystem(0,NULL,NULL,NULL,NULL); line it gives me the same error for PerformChat(“Carlos”,“Harry”, “Hello”,NULL,chatscript_answer);

From the Lite-C manual:

Error E1512: Empty prototype ...
An empty function prototype was called. This can happen when the function body is missing, or a function was called from a DLL that doesn’t exist or was not found. Check the acklog.txt - functions with missing bodies are listed there. A frequent cause of this error is using a plugin that could not be loaded on the target system - for instance, using ackphysX functions on a system where PhysX was not installed.

When using either of the functions I get an “Error1512 empty funcion”, so it seems it is not just the argv changes in InitSystem

 

 
  [ # 22 ]

I installed your engine on my machine. Reading the docs, it doesn’t appear to allow static libraries, so I’ll have to create a DLL chatscript instead. Then you need a header file and a defineAPI call to make the linkage happen. Back to you in a couple of days I expect.

 

 
  [ # 23 ]

I am so sorry for all the trouble I am causing you, and extremely gratefull for all the work you are putting into this to help me out. Thankyou very much Bruce!

 

 
  [ # 24 ]

I recieved your ChatScript.DLL and have been trying to get it to work. I have finally gotten rid of the syntax errors regarding my .h prototype declaration, and no longer get the E1512 errors (Calling Empty Prototype Function) either.
The script now loads fine withought errors, untill I try to call either of the two functions and get a E1513 (empty/invalid pointer).
I can’t seem to figure out what I am doing wrong with “DefineApi” that isnt setting the function pointer correctly to the dll.

My current “testing.c”:

#include <acknex.h>
#include <windows.h>
//#include <default.c>
#include "ChatScript.h"

void main()
{
 fps_max
=60;
 
level_load(NULL);
 
 
ChatScriptInit();
 
InitSystem(0,NULL,NULL,NULL,NULL);
 
//PerformChat(_chr("Carlos"),_chr("Harry"),_chr("Hello"),NULL,_chr(chatscript_answer));
 
 
while(1)
 
{
  wait
(1);
 
}

My current “ChatScript.h”:

#define PRAGMA_BIND "ChatScript.DLL"
unsigned int WINAPI InitSystem(int argcchar** argv,charunchangedPathL,charreadonlyPathcharwritablePath);
void WINAPI PerformChat(charusercharuseecharincoming,charip,charoutput);
STRINGchatscript_answer;

void ChatScriptInit()
{
   chatscript_answer
=str_create("#256");
   
InitSystem DefineApi("user32!InitSystemA");
 
PerformChat DefineApi("user32!PerformChatA");

Error E1513 from the 3DGS manual:

Error E1513: Script crash in…
A function of your script crashed. The usual suspects are accessing an empty pointer, accessing a non-empty pointer to a removed or nonexistent object, or performing an invalid operation such as dividing by 0.

Any clues as to what I am doing wrong with the DefineApi() calls? I have tried other variations of this, and tried with LoadLibrary(); GetProcAddress(), and with #define PRAGMA_API InitSystem;kernel32!InitSystemA… But I just don’t understand what I am doing wrong

 

 
  [ # 25 ]

Discouraging as that may sound, I believe that you’re making progress here, so keep at it. smile

 

 
  [ # 26 ]

Looking into other related stuff I tried the following in my main:
long test = GetModuleHandle(“ChatScript.DLL”);
The result in “test” is 0… I am guessing it means that the dll is not loaded in my application?
I am trying to look for another function I might be missing that could be needed to load the dll before the “DefineApi()” calls…

Thanks for the support Dave. I feel like I am in way over my head with this, sometimes it feels like I am just trying randomly with anything I find on the subject since I don’t have any prior knowledge about dll’s or how these api functions work. But I will keep trying.

 

 
  [ # 27 ]

I haven’t tried to figure out how to create code projects with your lite-c, only read docs on DLL stuff.  This code would be closest to what works in visual studio in my test app on the dll.

#include <acknex.h>
#include <windows.h>

void main()
{
fps_max=60;
level_load(NULL);
unsigned int WINAPI InitSystem(int argc, char* argv,char* unchangedPathL,char* readonlyPath, char* writablePath);
void WINAPI PerformChat(char* user, char* usee, char* incoming,char* ip,char* output);
long h = LoadLibrary("ChatScript.DLL");
InitSystem = GetProcAddress(h,InitSystem)
PerformChat = GetProcAddress(h,PerformChat)

InitSystem(0,NULL,NULL,NULL,NULL);
//PerformChat(_chr("Carlos"),_chr("Harry"),_chr("Hello"),NULL,_chr(chatscript_answer));

while(1)
{
wait(1);
}
}

 

 
  [ # 28 ]

I tried it but still get the same empty/invalid pointer error E1513. Also tried a variant with the functions outside of main():

#include <acknex.h>
#include <windows.h>

unsigned int WINAPI InitSystem(int argcchar** argv,charunchangedPathL,charreadonlyPathcharwritablePath);
void WINAPI PerformChat(charusercharuseecharincoming,charip,charoutput);
long ChatScript_h;
STRINGchatscript_answer;

void main()
{
 fps_max
=60;
 
level_load(NULL);
 
 
//while(!GetModuleHandle("ChatScript.DLL")){wait(1);}
 
 
ChatScript_h LoadLibrary("ChatScript.DLL");
 
InitSystem GetProcAddress(ChatScript_h,InitSystem);
 
PerformChat GetProcAddress(ChatScript_h,PerformChat);
   
   
chatscript_answer=str_create("#128");
 
InitSystem(0,NULL,NULL,NULL,NULL);
 
//PerformChat(_chr("Carlos"),_chr("Harry"),_chr("Hello"),NULL,_chr(chatscript_answer));
 
 
while(1)
 
{
  wait
(1);
 
}

I tried including a line that would wait for the dll to be loaded just to try it out but had to comment it out because it would get stuck there…

//while(!GetModuleHandle("ChatScript.DLL")){wait(1);} 

it seems the dll is never being loaded.
I also checked the log file that Lite-C generates and there is no sign of ChatScript.DLL being loaded in there.

NVIDIA GeForce GT 610 pure T&L device 1ff9 detected
D3D device NVIDIA GeForce GT 610 1ff9 selected.
ackAR.dll opened
acknet.dll opened
ackoal.dll opened
ackphysx.dll opened
ackwii.dll opened
Compiling TEST2.C - [Esc] to abort…..
InitSystem: function not found
PerformChat: function not found…. 0.302 sec
Running TEST2.C.
2 objects
Main started at 1.400 in debug mode
D3D_Init Window: 800x600 -> Window: 1x800x600x32
Video memory found: 3787 MB
LevelInit at 1.434 0 lmaps 0 textures…ok
LevelReady at 1.438
Error E1513: Script crash in main: 
Main loop at 2.899….
1st frame with 3787 MB. at 2.903
Normal exit at 4.385
Close level,DLL,objects

I have been searching the Lite-C forums and found some interesting stuff regarding DLL’s but I dont understand what they are saying. I think they are mostly talking about the dll code itself and not the .h file code:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=433131

I also created a new thread to see if we can get some answers with this issue:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=433549#Post433549

 

 

 
  [ # 29 ]

Obviously if the dll never gets loaded, all bets are off. You can presumably create an if that tests if the dll got loaded (variable set to nonzero) and print out if it fails.  If the dll fails to load then either:
1. the name of the dll is wrong (I don’t think so)
2. the current working directory is not ChatScript (you can try an absolute path to the dll OR you can try changing cwd to the chatscript directory.
3. the dll is faulty and cannot be loaded (I can load it in visual studio).

You need to get the dll loaded before anything else will function.

 

 
  [ # 30 ]

Oooh!  My favorite topic… Game A.I.  The issue may relate to trying to run an “unmanaged” C++ DLL in a “managed” Mono virtual machine game.  While on the topic of games…  I need a little help too… Please?

Think the judges will like this Italian model in the upcoming chatbot contests?

Says she’s a → Gamer Girl

 

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