Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: DoorKnobHandle on Wed 31/12/2008 14:25:10

Title: BUG: AGSE_KEYPRESS for plugins
Post by: DoorKnobHandle on Wed 31/12/2008 14:25:10
I am currently writing a plugin and when I try and react to keypresses trough the AGSE_KEYPRESS-event the following bug occurs:

Letters (for example a [65 or something]) only work when the user hits them with shift, it only works with capital letters - and not, as the plugin-manual says, just like in AGS. This should be easy to fix, right?
Title: Re: BUG: AGSE_KEYPRESS for plugins
Post by: Pumaman on Wed 31/12/2008 14:56:48
AGS doesn't automatically capitalize the letter keys when sending events to plugins -- so it will be 'A' (65) for upper-case A, and 'a' (97) for lower-case A.

This is by design, to allow the plugin more control over the input.
Title: Re: BUG: AGSE_KEYPRESS for plugins
Post by: DoorKnobHandle on Wed 31/12/2008 15:13:00
Oh, didn't know these lower-case versions starting from 97 exist at all. That makes sense. Thanks.

EDIT: Of course, then this description "ASCII value of keystroke, as text script on_key_press" in the plugin-manual is somewhat misleading though, maybe a star with a short clarification could prevent others from asking this again.
Title: Re: BUG: AGSE_KEYPRESS for plugins
Post by: Pumaman on Wed 31/12/2008 15:35:15
For both the script on_key_press and the plugin AGSE_KEYPRESS event, AGS passes straight through all ASCII keycodes between 32 and 126 (see ascii table (http://www.asciitable.com/).
The additional AGS-specific special keys are then documented in the manual.

The only difference is that for the script on_key_press event, AGS automatically converts lower case 'a'-'z' into the upper case versions so that people scripting don't have to worry about whether Caps Lock is on or not.

I will update the Plugin API page, thanks.
Title: Re: BUG: AGSE_KEYPRESS for plugins
Post by: DoorKnobHandle on Fri 02/01/2009 20:21:20
Ok, another thing I'm not so sure about: is it possible or expected that functions exported from plugins (such as the Add/Subtract functions in the template on acplugin.htm) can not take floats as return type (but as parameter it works)? Whenever I try to create a - say - float ReturnSomeFloat ( ) function, it gives me 0.0 or garbled values. Can somebody confirm? I'm pretty certain that I'm not doing something wrong at the moment.

Thanks ahead of time.
Title: Re: BUG: AGSE_KEYPRESS for plugins
Post by: Pumaman on Fri 02/01/2009 21:23:18
Even though float is a 32-bit data type, compilers like MSVC automatically push it as a 64-bit to/from functions. In the AGS engine some macros are used to get around this:

#define SCRIPT_FLOAT(x) long __script_float##x
#define INIT_SCRIPT_FLOAT(x) float x = *((float*)&__script_float##x)
#define FLOAT_RETURN_TYPE long
#define RETURN_FLOAT(x) return *((long*)&x)

They are then used like this:

int FloatToInt(SCRIPT_FLOAT(value), int roundDirection) {
  INIT_SCRIPT_FLOAT(value);

  // do stuff here, "value" is a C++ float
}


FLOAT_RETURN_TYPE IntToFloat(int value) {
  float fval = value;

  RETURN_FLOAT(fval);
}
Title: Re: BUG: AGSE_KEYPRESS for plugins
Post by: DoorKnobHandle on Sat 03/01/2009 16:55:30
Ah! Thanks, works like a charm!