Support having interaction handlers in any script module

Started by Crimson Wizard, Sun 22/09/2024 16:37:29

Previous topic - Next topic

Crimson Wizard

I gave a quick try to this long existing feature request, to support having object interaction and event functions in any script module besides Global Script.
https://github.com/adventuregamestudio/ags/pull/2534

Making this work on the engine's side was pretty simple. Although in the implementation that I tried engine tests every script for the matching symbol, which may make running interaction somewhat slower, depending on the number of modules. I doubt that would be a performance problem, since this uses fast lookup tables, and normally happens as a reaction to player input. But there's definitely a room for improvement here. Either the script name may be saved along with the function name during game compilation; I suppose that would be a reasonable thing to do. Or it may be cached at runtime after running the event for the first time (or do this in case compiled data does not contain a script name).

But frankly I was more bothered about Editor's side of this issue, where "..." should do something more than leading to a global script.

This made me step back and think that it may be a smarter thing to save script name alongside with the function name. In other words, have strings like "GlobalScript.asc::cEgo_Interact". And if it does not have a script name, then assume it's a GlobalScript. This might work well at least if saved in compiled game, but also may work if used in the events fields. Maybe...

I suppose further, that maybe the Editor may automatically copy the previously used script name from assigned events when you create a new handler. For example, if you have a Character, and you have already assigned a "MyCustomModule.asc::cEgo_Interact" for Interact event, then you press [...] button for Look event, editor will insert "MyCustomModule.asc::cEgo_Look". If there are multiple scripts names used in these events for some reason, then maybe the first found one is used (?).

I am posting these thoughts here, willing to make a small pause and think this over again, but maybe somebody has ideas too. Unfortunately, even though the ticket exists for a very long time now (https://github.com/adventuregamestudio/ags/issues/485), there was not much discussion of this. Unless there had been one on forums and I missed it.

Crimson Wizard

#1
Yesterday eri0o suggested to add a property for each object, telling which module to use for events.

I figured to make something, and made it displayed on Events tab, closer to events themselves, for convenience.

Furthermore, this property displays a automatically refreshed selection of script modules for global objects, and a fixed room script for room contents.



Pressing on [...] makes Editor go to the correct selected script module.

Snarky

Sweet! Sounds like a great solution. I like that a lot better than having the script name in the handler function name (especially if you move stuff around later).

eri0o

Oh, I didn't thought that issue was about this, for some reason I thought it was about triggering an event from a module - like event.Emit() will cause a listener to pick it, and I never had much use for this. But yeah, the events being able to assign a specific script module allows one to skip a redirection step in the global script to call the other modules.

In my head people would have script modules either for game wide systems or for game "areas", say three rooms where a puzzle involve things that exist between these areas. Then you would have some items that are specifically made to be used in this area and some GUIs related to these items, so this is the kind of use I would give for changing from the global script - plus I usually have a script module for my game menus and these GUIs would link to this script module directly.

I am curious how other people organize their games and if they would have similar uses.

Crimson Wizard

#4
If anyone likes to test, here's a ready build:
https://cirrus-ci.com/task/5179752720367616

This lets select script module for individual:
* Characters
* Inventory Items
* GUIs (note that gui controls don't have this selection and use their parent GUI's module)

Rooms and room objects just display a room script there, but you cannot change that.


SMF spam blocked by CleanTalk