inactive structure store.getUsedCapacity returns null



  • let x = the ID of an inactive lab (owned by a player who no longer owns the room's controller.)

    $ Game.getObjectById(x).store.getUsedCapacity()

    null

    $ _.sum(Game.getObjectById(x).store)

    3775

    I'd expect getUsedCapacity() to return 3775. Its return value shouldn't depend on the active status of the structure in which it's housed.

    ☝


  • It's a lab. It uses a constrained store that returns NULL if you don't ask what to look for in getUsedCapacity(); You can only make that call with no parameter with a general store, like in a storage or terminal.

    You have to figure out what's in it first. It will be energy and one mineral or compound.

    Edited to add: Ok, the solution is pretty obvious, actually, the property "mineralType" is not depreciated, so it will still be intended to work.. Simply calling "lab.store.GetUsedCapacity(RESOURCE_ENERGY); or lab.store.getUsedCapacity(lab.mineralType); to get the corresponding used capacity.



  • Okay. Thanks.

    That's very much not the design I've have chosen. But I cannot deny that the implementation is consistent with what's written in the docs.



  • I thought the same thing at first, but it makes total sense. There is a "Data Legacy" here that needs to be maintained. In the case of the labs, sure... it's TOTAL capacity is 5K, but it's always partitioned off into a 2K segment for energy, and a 3K segment for whatever mineral is stored there.

    So if you just say "lab.getUsedCapacity();" which do you mean? Energy or Mineral? Getting both munged into one number is useless, as you can't use that to determine how much MORE of either energy or mineral will fit into there.

    You can still "general purpose algo" it with a for loop that iterates the store's keys, of course, if your goal (As yours is here.) is to simply drain everything from it. And... not only does that work for all stores, (Except for the super weird bird, Nukers.) but you couldn't do that before with many of them..



  • So if you just say "lab.getUsedCapacity();" which do you mean? Energy or Mineral? Getting both munged into one number is useless.

    If I mean specifically energy, I can write getUsedCapacity(RESOURCE_ENERGY).

    getUsedCapacity() with no argument seems like it ought naturally to return the total capacity used, of all sorts.



  • The same issue occurs in TOMBSTONEs.

    • Game.getObjectById("X").store.getUsedCapacity() = null
    • Game.getObjectById("X").store.getUsedCapacity(RESOURCE_ENERGY) = 207

    Hmm..


  • Dev Team

    It should be fixed now on the official server, and on community servers starting from version 4.1.5.

    👏