1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Taleden's Inventory Manager

Discussion in 'Programming (In-game)' started by taleden, Nov 1, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. taleden

    taleden Trainee Engineer

    Messages:
    48
    Latest version: 1.5.0 (2016-05-24)
    Steam Workshop Page
    User's Guide

    Taleden's Inventory Manager (TIM) is an in-game script which automates the management of your inventory, refineries and assemblers. It combines and expands on the functionality of the Automated Inventory Sorting mod and the Crafting Components Quotas and Refinery Manager scripts, offering all of their basic features and more:
    • Sort items into containers with priorities and target quantities, just like AIS, but as an in-game script instead of a separate mod, and also with proportional allocation: if there aren't enough Uranium ingots (for example) to meet every reactor's target, they'll each get the same percentage of their target, instead of allowing one to take more than its share and starve the others.
    • Keep all refineries working, just like RM, but also with smart prioritization: the ore whose ingot is most under-quota will always be refined first, possibly by several refineries, to ensure you're never starved for one material while all your refineries are blindly refining something else.
    • Meet component quotas by automatically switching dedicated assemblers on and off, just like CCQ, but also with flexible, adaptive quotas: in addition to the flat minimum quantity, each item also has a target percentage of all items of that type, so as you amass more total items, the effective quotas will all go up accordingly without you having to update them yourself all the time. Plus, all of your blocks' item sorting requests (such as reactors wanting uranium, weapons wanting ammo, etc) count as implicit quotas, so if you build more reactors and set their fuel allocations, that will automatically cause your refineries to prioritize uranium as needed to keep all your reactors fueled.
    • Display summaries of your inventory on text panels, just like AIS and many LCD scripts, but also with knowledge of all the other comonents of the unified system: progress bars are based on the item's "effective quota" which is the highest of its flat, percentage and implicit quotas, and there's a column to show how many refineries or assemblers are currently assigned to producing that item (as applicable).
    • Configure everything with tags in block names, but also with greater convenience and compatibility: you can use abbreviations for any item type (as long as they're un-ambiguous), you can have TIM re-write your tags in standard format to help make clear which rules have been understood correctly and which need to be corrected, and you can set a unique prefix to distinguish the tags TIM should parse, to avoid conflicting with any other mods that also require tags in block names.
    The script is published on the Steam Workshop, and a complete User's Guide is also available.

    Comments, questions, suggestions and bug reports are welcome!
     
    Last edited: May 24, 2016
    • Like Like x 3
  2. Harrekin

    Harrekin Master Engineer

    Messages:
    3,077
    Thank you for posting it, I'm newish to coding so I'm always interested to see how other people do stuff compared to how I'd imagine I myself with my limited knowledge.

    Looks pretty good :)
     
  3. taleden

    taleden Trainee Engineer

    Messages:
    48
  4. codetodi

    codetodi Trainee Engineer

    Messages:
    26
    Hey,

    I just looked at your code and was wondering: did you encounter any complexity issues? What are the limits of your script?

    Cheers
     
  5. taleden

    taleden Trainee Engineer

    Messages:
    48
    I have never encountered the complexity error, but I also don't have any really enormous worlds on hand to test with. I'm hoping it will be fine because I've taken care to avoid doing the same work twice (I noticed for example that some scripts scan items by going through a list of items, and then for every item, scanning every stack in every inventory to see if it's the item it wants -- that means scanning every inventory dozens of times, which is a waste).

    I'd love to hear any feedback on how it works for large setups; if there are complexity issues, I can certainly add some logic to split up the work across multiple runs instead of trying to do everything every time.
     
  6. taleden

    taleden Trainee Engineer

    Messages:
    48
    Updated to v1.1.0:
    • Added the tag keyword "FORCE" to set item sorting requests even for types that the block should not allow. This can be used to manage mod-added blocks which break the usual rules of their block type, such as Refineries that process Gravel, which is an Ingot: "Refinery [TIM Ingot/Stone]" is rejected because TIM knows that's usually impossible, but "[TIM FORCE:Ingot/Stone]" will attempt to send Gravel there anyway.
    • Added the tag keyword "SPAN:width:height" for panels (where "width" and "height" are positive integers) to extend their content onto additional panels below and to the right of the tagged panel (which will be the upper-left corner of the spanned display). Quota panels cannot yet be spanned.
    • Panel font sizes are now automatically reduced to accommodate the displayed data (accounting for the multi-panel span, if any).
    • Improved item restriction handling for blocks which accept more than one type but not all types.
    • Fixed detection of block variants (Arc Furnaces, Hydrogen Tanks, Wide LCDs) when the game interface is set to a language other than English.
    • Delayed quota processing until run #2 and item sorting to run #3 to further reduce the chance of hitting the script complexity limit.
    • Removed quota re-writing; invalid quota panel lines will instead be written to the debug panel, if any.
    • Removed past changelog entries from the script header to save space. The full change history is available on the Workshop page.
    • Added the ghost in the machine.
     
  7. Harrekin

    Harrekin Master Engineer

    Messages:
    3,077
    Can I have permission to use the character spacing info in your script dude?

    I'd feel like a d**k not asking...
     
  8. taleden

    taleden Trainee Engineer

    Messages:
    48
    Sure, go right ahead. A little mention of its source on the docs for whatever you're making would be appreciated of course. :)
     
    • Agree Agree x 1
  9. HumbleOverlord

    HumbleOverlord Trainee Engineer

    Messages:
    9
    Patch yesterday broke TIM, is it a SE bug, or does TIM need to be adjusted?
     
  10. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    Looks pretty awesome. I have a couple questions.

    How does it deal with connected ships (both via connector and/or mergeblock)?

    Also does it understand conveyor sorters? Say I have some 4e refineries and some 4p refineries and I have sorters blacklisting certain ores from each. Is the script going to be aware of that and only send to appropriate refineries or is it going to puke all over itself?
     
  11. taleden

    taleden Trainee Engineer

    Messages:
    48
    Yes; it's a quick fix to get it running again, but I'm also working on fixing a few other bugs, so the update will hopefully be published in the next day or two.

    TIM currently sees all connected grids (via locked connector or merge) as one grid, so any tagged containers etc. that are accessible in the terminal through any kind of connection will also be managed by TIM. When the connection is broken, they will disappear from TIM's view and the next time it runs, it will behave accordingly.

    Sorters won't break TIM, but as far as I know, they will also not be honored by TIM, because there's no way for a script to know where a sorter is or what items it's meant to block. The in-game scripting API provides functions that TIM uses to move items around, but those functions ignore the presence of sorters, so if TIM thinks you want items moved across a sorter that should otherwise forbid it, those items will move nonetheless. The solution is to write your block tags so that TIM knows what you want it to do, for example by tagging your refineries with the specific ores you want each one to work on, rather than using the general "[TIM Ore]" tag which will allocate ores according to your inventory levels (but with no regard to which modules are attached to each refinery, because I don't know of a reliable way to access that in the scripting API).
     
    • Like Like x 1
  12. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    Thanks.

    One more question about the grids then. Is there anyway to override this behavior? For example if I connect 2 ships both running TIM. What happens then?
     
  13. taleden

    taleden Trainee Engineer

    Messages:
    48
    Currently the best solution here is to configure each instance of TIM with a different prefix, using the script argument "prefix=myprefix" on the two programmable blocks. If the prefixes are different, then each instance will ignore the tags on the other grid when they become visible after docking. In the latest released version (1.3.1) you'll also have to use two prefixes which are not prefixes of eachother -- for example, "prefix=TIM" and "prefix=TIM2" will be a problem, because "TIM2" starts with "TIM". So instead you'd need something like "prefix=TIM1" and "prefix=TIM2". That bug should be fixed in the next release, however.
     
    • Like Like x 1
  14. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    That's what I was looking for, pretty much like the LCD script does. Awesomesauce.
     
  15. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    So I'm a little unclear on setting this up. Read through the guide, but either it can't do some things I'd like to do or I'm just not getting it.
    Does anyone have anything on the workshop that is a good example of this script in use?

    So I've got this setup:
    6 refineries 4 efficiency (current sorters, which I understand I need to convert to tags: blacklist- Fe, scrap, stone, Si)
    2 refineries 2eff/2 prod (blacklist - U, Pt, Ag, Au, Mg)
    Some arcs.

    So I'm not understanding how I tag these (I probably need to give the guide another good read through).
    Also, can I prioritize the lists as well or is that too complex? Like Ni/Co/Fe goes to arcs unless refineries are idle, or is it just going to distribute among all available to it?
     
  16. Custardicus

    Custardicus Trainee Engineer

    Messages:
    15
    Thanks for the script its just awesome pity you cannot control Assemblers quite as well as Refineries because of the API
     
  17. noxLP

    noxLP Junior Engineer

    Messages:
    729
    Hey @taleden , i need a bit of help with your script, i have some small ship turrets, reloadable missile launchers and gatlings in one small ship, trying to use your script to reload them all without priority, all of them with a name like: NameOfBlock [TIM ammomagazine:X], X for the amount of ammo.
    Tim only reacts to one of the turrets (gatling turret) changing the ammomagazine tag to the NATO magazines in capital letters, the rest of the blocks stays at lower case and nothing happens. I don't understand why the script works ok with only one of the turrets when all the blocks have the same tag :eek:ops:

    Should I just establish priorities for it to work correctly or am I doing something wrong with the tags?


    Edit: Btw, i have it with a 1sec timer, meybe the script need more time?
     
  18. Burillo

    Burillo Junior Engineer

    Messages:
    648
    to solve the problem of multiple grid connections, try stealing my grid locality code from BARABAS (which is a pretty similar script but has a slightly different target use case). that way you can have your script running on however many ships/bases you want and they won't interfere with each other.
     
  19. noxLP

    noxLP Junior Engineer

    Messages:
    729
    No problem, it got solved by itself :stare: without me doing anything, it just works now...
     
  20. taleden

    taleden Trainee Engineer

    Messages:
    48
    Thanks for the suggestion! I did actually add support for controlling how TIM behaves across connected grids, I just forgot to update this thread. It's covered in the Connected Grids section of the User's Guide on Steam.

    I also just published v1.5.0 which adds quota stabilization, which will hopefully yield more intuitive behavior for the dynamic/percentage quotas.

    Unfortunately Keen still hasn't fixed the cockpit inventory bug or added proper support for assembler management. Maybe next time.
     
  21. Roygul

    Roygul Trainee Engineer

    Messages:
    2
    Love your script, must have in all my games. I noticed that nanite control factory seems to have a way of managing assemblers to produce parts. Thought it might help.(Thou its prob because its a mod and not a script).

    Cheers
    Roygul
     
  22. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    Any chance they added the needed functions again?
     
  23. Malware

    Malware Master Engineer

    Messages:
    9,867
    What functions would that be?
     
  24. Phoera

    Phoera Senior Engineer

    Messages:
    1,713
    yes, mods have access to assemblers queue.
    i have added some of them for PB in my mod, but i am not sure if it still works.
     
  25. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    Oh...I don't remember exactly. I just remember Taleden saying he couldn't make TIM work again until they added whatever back, was in changelog and a bug report.
     
  26. Malware

    Malware Master Engineer

    Messages:
    9,867
    (@taleden)
    Because there was a bug in the whitelister. If that fix is out then it shouldn't be a big deal to make this work with Dev. He should have a single error to fix, which is easy. I tested with TIM.
     
  27. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    Something about block ownership. Sec. I'll go find it.
    https://forum.keenswh.com/threads/01...sbetweenplayerandblock-is-prohibited.7385610/
     
  28. Malware

    Malware Master Engineer

    Messages:
    9,867
    Yes, those. I think I fixed that.
     
  29. bladedpenguin

    bladedpenguin Apprentice Engineer

    Messages:
    207
    Hello, trying to debug this script. I'm running it on the dev version (1.145) and I changed
    void ScanBlocks<T>()
    to
    void ScanBlocks<T>() where T: class
    which makes the script run for the most part. I'm now getting an exception whenever I show up with a cockpit full of ore. 50% of the time it loads it into the refineries jsut fine, but the rest of the time I get an exception: "Object Reference not set to an instance of an object"

    Is there any way to find out which method call threw the exception?

    Apologies for bothering everybody. I'm not a C# dev, I work mostly with Java and Node.js
     
  30. Krougal

    Krougal Senior Engineer

    Messages:
    1,012
    Yeah, so I stumbled on that myself last night (someone put it on the Steam comments). Haven't had a chance to poke around with the rest of it.
    Does Tal know it's fixable? I know he was interested initially in keeping it working for dev even but I suspect he got disgusted when it went unresolvable for a few patches and maybe is taking a break. Looks like he hasn't been around since the 7th.
     
Thread Status:
This last post in this thread was made more than 31 days old.