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

👼 Script: Log meaningful error upon callback mixup. #3081

Merged

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Sep 3, 2023

One point for @Xploder98 in a friendly Devs vs. Users match :)

Long story short, Xploder mixed up callbacks and the game obligued which resulted in script failure with error asCONTEXT_NOT_PREPARED. This hapenned because our callback system is very confusing:

  • we have a legacy "script handler" mechanic in .TOBJ file and classic game.spawnObject(), where you pass a function name and it gets invoked on eventbox collision.
  • we also have recently introduced SE_EVENTBOX_ENTER and SE_EVENTBOX_EXIT which work with the classic event callback mechanism eventCallback() (and the extended eventCallbackEx() version) - it does the same job and even provides some extra data. This works independently of the "script handler" mecahnic described above - you just do game.registerForEvent(SE_EVENTBOX_ENTER) and you're covered, for all objects.

Changes made:

  • clarified the legacy eventbox callback in docs on 'developer.rigsofrods.org' (will update when this commit/PR is merged).
  • Added a "this is obsolete" notice to AngelScript.log, see below.
  • Added a sensible "did you make a typo in arguments?" notice to AngelScript.log, see below.

Example AngelScript.log if you mix up the callbacks:

13:03:15: spawnObject(): Specifying event handler function in `game.spawnObject()` is obsolete and only works with terrain scripts; Use `eventCallbackEx()` with event `SE_EVENTBOX_ENTER` instead, it provides the same data and works with any script. Just pass an empty string to the `game.spawnObject()` parameter.
13:03:15: Warning: a callback function with signature 'void eventCallback(int, string, string, int)' was not found but a function with given name exists: 'void eventCallback(int, int)' - did you make a typo in arguments?

What needs to be tested:

  • Terrain scripts should work normally: check races, spawners and truckshops.
  • Custom scripts like 'demo_script.as' or 'road_editor.as' should work normally.

One point for Xploder98 in a friendly Devs vs. Users match :)

Long story short, Xploder mixed up callbacks and the game obligued which resulted in script failure with error asCONTEXT_NOT_PREPARED. This hapenned because our callback system is very confusing:
* we have a legacy "script handler" mechanic in .TOBJ file and classic `game.spawnObject()`, where you pass a function name and it gets invoked on eventbox collision.
* we also have recently introduced `SE_EVENTBOX_ENTER` and `SE_EVENTBOX_EXIT` which work with the classic event callback mechanism (and the extended `eventCallbackEx()` version) - it does the same job and even provides some extra data. This works independently of the "script handler" mecahnic described above - you just do `game.registerForEvent(SE_EVENTBOX_ENTER)` and you're covered, for all objects.

Changes made:
* clarified the legacy eventbox callback in docs on 'developer.rigsofrods.org' (will update when this commit/PR is merged).
* Added a "this is obsolete" notice to AngelScript.log, see below.
* Added a sensible "did you make a typo in arguments?" notice to AngelScript.log, see below.

Example AngelScript.log if you mix up the callbacks:
```
13:03:15: spawnObject(): Specifying event handler function in `game.spawnObject()` is obsolete and only works with terrain scripts; Use `eventCallbackEx()` with event `SE_EVENTBOX_ENTER` instead, it provides the same data and works with any script. Just pass an empty string to the `game.spawnObject()` parameter.
13:03:15: Warning: a callback function with signature 'void eventCallback(int, string, string, int)' was not found but a function with given name exists: 'void eventCallback(int, int)' - did you make a typo in arguments?
```
apparently there was a glitch in the logging, first map would have script loading silenced, but any next would be noisy.
also explicitly silenced the warning about legacy callback.
@ohlidalp ohlidalp force-pushed the exploder_eventbox_asCONTEXT_NOT_PREPARED branch from f7f5e41 to 4a84b67 Compare September 26, 2023 02:16
@CuriousMike56
Copy link
Collaborator

Tested:
Truckshops ✅
Races ✅
Demo script ✅
Road editor ✅
Script editor ✅

Only new warning I've seen is on the "GPU benchmark" terrain (Benchmark.zip) where every tree spawned shows:
[RoR|Script|Notice] Warning: a callback function with signature 'void e(int, string, string, int)' was not found
The script still works as normal.

@ohlidalp ohlidalp merged commit 3c47c6c into RigsOfRods:master Oct 14, 2023
2 checks passed
@ohlidalp ohlidalp deleted the exploder_eventbox_asCONTEXT_NOT_PREPARED branch October 14, 2023 17:45
@ohlidalp ohlidalp mentioned this pull request Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants