GetScriptFunctionAddress Help...

Started by Chernsha, Wed 18/02/2004 20:53:47

Previous topic - Next topic

Chernsha

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

a-v-o

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);

Kweepa

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);

Still waiting for Purity of the Surf II

Chernsha

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

Scorpiorus

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


Kweepa

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.
Still waiting for Purity of the Surf II

Scorpiorus

I could swear I happened to display a constant string with the length of about a dozen of characters. Or is it just GetTextHeight?!

Kweepa

I dunno, but better safe than sorry, eh?
Still waiting for Purity of the Surf II

Chernsha

that is work ok.
Thanks for your support. :)

SMF spam blocked by CleanTalk