Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: on Wed 18/02/2004 20:53:47

Title: GetScriptFunctionAddress Help...
Post by: on Wed 18/02/2004 20:53:47
I try to write the GetScriptFunctionAddress Function in the Plugin Code.
But I alway get a error message while run in AGS.

the code example in VC++:

int resultHeight;
int (*func_ptr)(char *text, int font, int width);
func_ptr=(int(*)(char*, int, int))engine->GetScriptFunctionAddress("GetTextHeight");
resultHeight=(*func_ptr)("test", 0, 5);

Can anyone tell me how to resolve the problem?
Thanks......
Title: Re:GetScriptFunctionAddress Help...
Post by: a-v-o on Wed 18/02/2004 21:10:43
which error message(s) do you get?

maybe it is:
resultHeight=func_ptr("test", 0, 5);

on the other hand, there is the following plugin api function if you want to get the height (and width):

void GetTextExtent (int font, const char *text, int *width, int *height);
Title: Re:GetScriptFunctionAddress Help...
Post by: Kweepa on Wed 18/02/2004 22:59:53
Have you put
engine->RegisterScriptFunction("AGS_FunctionName", CPP_FunctionName);
in the engine startup function?

This worked for me...

// ****** RUN TIME ********

IAGSEngine *engine;

int GetTextExtentX(int font, const char *text) {
 long x;
 engine->GetTextExtent(font, text, &x, NULL);
 return x;
}
int GetTextExtentY(int font, const char *text) {
 long y;
 engine->GetTextExtent(font, text, NULL, &y);
 return y;
}

void AGS_EngineStartup (IAGSEngine *lpEngine) {
 engine = lpEngine;

 // Make sure it's got the version with the features we need
 if (engine->version < 3) {
   engine->AbortGame ("Engine interface is too old, need newer version of AGS.");
 }

 engine->RegisterScriptFunction ("GetTextExtentX", GetTextExtentX);
 engine->RegisterScriptFunction ("GetTextExtentY", GetTextExtentY);

Title: Re:GetScriptFunctionAddress Help...
Post by: on Thu 19/02/2004 06:03:43
Thanks for your response....

The code is just a example.I try to write other function call,but I still get the error message.

I try your advice but the result is the same.
resultHeight=func_ptr("test", 0, 5);

The message is :
Illegal exception
----------------------------------------------------------------
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x0041FF98 ; program pointer is -42, ACI version 2.60.698, gtags (2039,34)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and notify CJ on the Tech forum.

(Global script line 18)


Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.
---------------------------------------------------------------------------

the Global script line 18 call my plugin function which run GetScriptFunctionAddress API.

Can anyone provide me the example of GetScriptFunctionAddress API which can run well in VC++.
Thanks......
Title: Re:GetScriptFunctionAddress Help...
Post by: Scorpiorus on Thu 19/02/2004 20:11:35
hmm, I just tried and for some reason calling "GetTextHeight" doesn't work unless it's text width parameter < 2 :P (a bug probably)

but yes the overall code is correct

btw, GetTextWidth seems to work fine, for instance:

typedef int (*FUNCTYPE)(const char*, int font);

FUNCTYPE pFunc = (FUNCTYPE)engine->GetScriptFunctionAdress("GetTextWidth");

int result = pFunc("blah blah blah", 0);

~Cheers

Title: Re:GetScriptFunctionAddress Help...
Post by: Kweepa on Thu 19/02/2004 20:43:58
Oh sorry, I see.
You're doing the right thing.

Ok, here's what you need to do:

char text[256];
sprintf(text, "test");
resultHeight = func_ptr(text, 0, 100);

It seems AGS *requires* that strings are at least 200 chars long.
Title: Re:GetScriptFunctionAddress Help...
Post by: Scorpiorus on Thu 19/02/2004 21:52:35
I could swear I happened to display a constant string with the length of about a dozen of characters. Or is it just GetTextHeight?!
Title: Re:GetScriptFunctionAddress Help...
Post by: Kweepa on Fri 20/02/2004 00:34:55
I dunno, but better safe than sorry, eh?
Title: Re:GetScriptFunctionAddress Help...
Post by: on Fri 20/02/2004 05:27:33
that is work ok.
Thanks for your support. :)