Alnivel wrote: ↑Mon Oct 16, 2023 10:47 pm
I got the impression that there are only two priorities, "highest" and "lowest", one of them is used if you don't specify a priority explicitly. Besides clarifying this on the wiki, I also think it would be clearer if there were a default and explicit "normal" ("normalest"?) priority.
Good call. The "normal" priority is implied, but probably not clear enough in the documentation.
Alnivel wrote: ↑Mon Oct 16, 2023 10:47 pm
And a question rather out of curiosity than as suggestion, but is there some reason/intention why a priority has three levels and not just an integer?
Two reasons. 1: I thought it would be easier to understand. I can never guarantee one script will be run first, given the unpredictable order in which startUp scripts are run, so just having a "highest" or "lowest" seemed the best call rather than using some sort of integer. 2: I didn't want to do array sorting, and instead opted for a methodology that inserts items into the array at the most ideal spot based on the priority.
To get even more technical, when I'm running through the array to run the functions, I'm doing it from the bottom up. That is, I'm starting at the last item, and then working my way towards the top, with the last callback being at index 0. When you add a callback with the highest priority, it is added to the bottom of the array. When you add a callback with the lowest priority, it is added at the top of the array, at index 0. If you don't specify a priority (ie "normal" priority), it is added just after the last "lowest" priority, basically between any lowest and highest priority items, if there are any. If you add a "normal" priority item, and there's no lowest priority items in the list already, it will be added to the top of the array, at index 0.
Now, if two callbacks are added with the highest priority, the last one added (ie. at the bottom of the array) will be the first one that is actually run. And the last lowest priority added will be the last callback run. As mentioned, I can't determine the order of startUp scripts, which would determine which functions would be last and which would be first. Using an integer as a priority I feel would give a false sense of security: If I add my callback with a priority of "0", which for arguments sake we'll call the highest priority, and another script adds a callback at the same priority, you end up in the same position (two scripts wanting the highest priority), but both thinking they should have been first. By using the more generalised "highest"/"lowest" descriptors, I think it communicates the outcomes a little better.
Alnivel wrote: ↑Mon Oct 16, 2023 10:47 pm
Another suggestion is to add try-catch inside the loop in the $process function - if one of the callbacks breaks, the others will be able to keep working.
Good call. Next version will have this.
Alnivel wrote: ↑Mon Oct 16, 2023 10:47 pm
Also, the Smugglers page still suggests setting "smugglers_illegalmarket.js" as a market script if you want to add support to a new commodity, looks to me like it needs updating.
Nice catch. Yep, I'll add it to the list.