BUG: AGSE_KEYPRESS for plugins

Started by DoorKnobHandle, Wed 31/12/2008 14:25:10

Previous topic - Next topic

DoorKnobHandle

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?

Pumaman

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.

DoorKnobHandle

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

Pumaman

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

DoorKnobHandle

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.

Pumaman

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

DoorKnobHandle

Ah! Thanks, works like a charm!

SMF spam blocked by CleanTalk