Scripting: add object pointer and verb parameters to object interaction functions #2061
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Hotspots have 2 special events without CursorMode param, these are "Walk onto" and "Mouse over":
Regions do not have CursorMode parameter, because their event types are different, not related to interaction mode:
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.