How can i pass a string between AGS and the plugin API?
How do i pass a managed type like a string?
AGS -> plugin
Let's say you have a plugin function that returns a string like this:
import void SetString(String input);
that would translate to:
void SetString(const char *input)
{
// here you can just use input as a regular null terminated string.
}
plugin -> AGS
Let's say you want to retrun a string from a plugin function like this:
import String GetString();
that would translate to:
const char *GetString()
{
return (engine->CreateScriptString(...));
}
Note that you need to use the CreateScriptString function for all strings you return.
Thanks Wyz!
Also below excerpt from the AGS plugin API documentation (http://adventuregamestudio.co.uk/acplugin.htm) should be kept in mind:
"The text script currently supports char, short and int types. These are 1, 2 and 4 byte integers respectively. Text script strings are implemented as standard C-style char* pointers, but with preallocated buffers of 200 bytes per string. Therefore, if you write a function which takes a string from the text script, make sure that if you add anything to it you don't write past 200 characters, or problems will result."
So I think we can safely declare and use character arrays of about 205 characters for passing strings between engine and plugin.
Ooh, I should remove that. That 200-byte thing refers to old style "string" variables, not to the newer "String" variables in newer versions of AGS.
Wyz has given the answers you need, anyway!