Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting: add object pointer and verb parameters to object interaction functions #2061

Merged

Conversation

ivan-mogilko
Copy link
Contributor

@ivan-mogilko ivan-mogilko commented Jul 21, 2023

Resolves #1765

I believe this is decade overdue...
This adds 2 optional parameters to all of the interaction event callbacks in AGS: object's pointer and a verb (aka cursor mode).
The purpose is to be able to distinguish object and interaction type when user links same function to multiple events. This is similar to how GUI events have GUI/Control and mouse button as parameters.
Right now the users have to resort to ugly workarounds, like calling GetAtScreenXY extra time (which is unreliable), or saving the interacted object in a global variable in on_mouse_click.

The event functions will have following prototype for Characters, Objects, Hotspots and InventoryItems:

function cEgo_Interact(Character *c, CursorMode mode)

Hotspots have 2 special events without CursorMode param, these are "Walk onto" and "Mouse over":

function hHotspot2_MouseMove(Hotspot *h)

Regions do not have CursorMode parameter, because their event types are different, not related to interaction mode:

function region0_WalksOnto(Region *r)

Code-wise the PR is ~50% code refactor.

Backwards compatibility

This change is fully backwards compatible, in the sense that script will work even if these parameters were omitted. This was achieved by some of the previous changes in 3.6.0 (related to on_key_press), which lets engine to ignore superfluous parameters not matching the function declaration in user script. But it's worth testing this of course.

Characters, Objects, InventoryItems and Hotspots will pass 2 params: an object's pointer and a interaction mode;
Regions have special interaction events, so will only pass 1 param: an object's pointer.
Room events pass no params, as before.
@ivan-mogilko
Copy link
Contributor Author

Two Hotspot events that do not work properly:

  • Walk On
  • Mouse Over

they are handled differently in the engine, and will need to be fixed. Their parameters should exclude CursorMode, and only have Hotspot pointer.

@ericoporto
Copy link
Member

Playing a bit with this, it does look the parameters are indeed optional when linking. After this is in, should the templates be updated? I mean for things like (perhaps there are more places...)

function cEgo_Interact(Character *c, CursorMode mode)
function cEgo_Look(Character *c, CursorMode mode)
function cEgo_Talk(Character *c, CursorMode mode)

@ivan-mogilko
Copy link
Contributor Author

After this is in, should the templates be updated?

That would be nice to have a reference, yes.
If you think it's necessary to give an example of using this argument, one of these placeholder functions could refer Character.Name in displayed text somehow.

@ivan-mogilko ivan-mogilko merged commit 541869c into adventuregamestudio:master Jul 26, 2023
25 checks passed
@ivan-mogilko ivan-mogilko deleted the 361--callbackargsex branch July 26, 2023 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script API: add object pointer argument to all "interact" callbacks
2 participants