Scripting API issue missing a function?

Started by ninekorn, July 19, 2017, 01:29:35 AM

ninekorn

Hi. just this little detail before I go sleep.

GetStationShopContainerId() is not working. is there another solution? i need the shop containers.

nine

ai_enabled

items.GetStationShopContainerId(stationId)
- it should work fine.

ninekorn


ai_enabled

Does it work properly now?
Why did it not work properly before? I guess you used wrong scope ("station." instead of "items.")?

ninekorn

nope still not working. I got my systems/stations but i cant get the shop sections. trying to figure it out right now.

Im wondering if I should get the list of items from the station first then get their containerID but still i didnt figure out how to do that either. Im searching now for

GetItemsAndCargo() but that one doesnt work either... Like you say im probably using the wrong scope but i didnt knew I had to use a scope for those. hmmm. im gonna try that right now lol its because that wiki "item" page lacks the examples haha. I couldnt find any scripts which uses those 2 functions either to show me how its done  ;D

ai_enabled

I recommend using Notepad++ and its multi-file search feature (Ctrl+Shift+F, Find in files). Just configure it to search in the data folder and it will find you at least two usage examples of items.GetStationShopContainerId

ninekorn

wow Notepad++ is powerful. I found itérations of items.GetStationShopContainerId in the StarTrek mod files package. I will look into it! Thank you very much for this hint i know what tool to use now to search. I was typing ctrl+F Inside each script lol much needed upgrade ;D

ai_enabled

Sure, I'm glad to help.
There is a good example of this function:
core\data\topics\fanatics\fanatics_quest_reputation.js
Line 362: var shop_container_id = items.GetStationShopContainerId(stationId);

(then an item added to this container).

ninekorn


ninekorn

#9
I've still got a problem trying to remove from the array all systems that have no stations. I know this is more related to Scripting knowlege but if you can help. It's for a new mod. So I have tried a lot of different functions and this one seems to almost be working but doesnt remove some systems that have no stations. I don't really understand why.

i could also put in game.GetSystemBases(systemList) != null && game.GetSystemBases(systemList) != undefined
it seems that the systems that have no stations are still logged as strings or something Inside the game.GetSystemBases function. its just weird. Im gonna keep trying some stuff but if anyones got any ideas I might be able to release this mod tonight. I gotta work hard though. Theres lots of stuff left to do in it.

                 for (var i = 0; i< systemList.length;i++)
      {
         if (game.GetSystemBases(systemList) == !/\S/)
         {
            var indexToRemove0 = systemList.indexOf(systemList);
            systemList.splice(indexToRemove0,1);
         }
      }

Edit: I tried
    game.GetSystemBases(systemList) == !/\S/
|| game.GetSystemBases(systemList) !=null
|| game.GetSystemBases(systemList) != " "
|| game.GetSystemBases(systemList) != "" 

but still got systems that are not beeing remove from the splice Method. Im still searching.


ai_enabled

GetSystemBases() returns array.
In programming, if a method is expected to return an array, it must return an array even if it's empty. It could return null only in the case when it's explicitly mentioned about this in the method comment/description (but it's very rare and happens only if library highly optimized to reduce overhead as much as possible; usually it's cheap to return an empty array).

So it returns an empty array when there are no stations at the system. You need to simply check if the length of this array is zero.

ninekorn

 i had tried it in the past but it didnt work for some reasons. weird. Ill try it again. maybe i had done a typo or something. Thank you for pointing the solution out.

ninekorn

#12
 mmm. still not working. Ill keep searching for a solution.             

                systemList = generator.GetAllSystems();

      for (var i = 0; i< systemList.length;i++)
      {
         if (game.GetSystemBases(systemList) == !/\S/
         || game.GetSystemBases(systemList) == null
         || game.GetSystemBases(systemList) == " "
         || game.GetSystemBases(systemList) == ""
         || game.GetSystemBases(systemList) == undefined
         || game.GetSystemBases(systemList) == "undefined")
         {
            var indexToRemove0 = systemList.indexOf(systemList); ---- with dual closing brackets with i of course.
            systemList.splice(indexToRemove0,1);
         }

         var tempBasesArray = game.GetSystemBases(systemList); ---- with dual closing brackets with i of course.
         if (tempBasesArray.length === 0 || tempBasesArray.length == 0)
         {
            var indexToRemove0 = systemList.indexOf(tempBasesArray);
            systemList.splice(indexToRemove0,1);
         }
      }


EDIT: so weird. I must be doing something wrong because its still not working with this.

for (var i = 0; i< systemList.length;i++)
      {
         if (game.GetSystemBases(systemList) == !/\S/
         || game.GetSystemBases(systemList) == null
         || game.GetSystemBases(systemList) == " "
         || game.GetSystemBases(systemList) == ""
         || game.GetSystemBases(systemList) == undefined
         || game.GetSystemBases(systemList) == "undefined")
         {
            var indexToRemove0 = systemList.indexOf(systemList);---- with dual closing brackets with i of course.
            systemList.splice(indexToRemove0,1);
         }

         var tempBasesArray = game.GetSystemBases(systemList);---- with dual closing brackets with i of course.

         console.Print(tempBasesArray.length + " " + " stationListArray");

         if (tempBasesArray.length === 0 || tempBasesArray.length == 0)
         {
            if (tempBasesArray == systemList)    ---- with dual closing brackets with i of course.
            {
               var indexToRemove0 = systemList.indexOf(systemList);---- with dual closing brackets with i of course.
               systemList.splice(indexToRemove0,1);         
            }         
         }
         
      }

ai_enabled

#13
UPD. So it was parser which removed i in square brackets. Ok, next time use BB code for your code as I mentioned below.

Proper code:

// remove all system IDs from systemList which don't have any spacestations
for (var index = 0; index < systemList.length; index++)
{
     var systemId = systemList[index];
     var systemBases = game.GetSystemBases(systemId);
     if (systemBases.length == 0)
     {
         systemList.splice(index, 1);
         index--;
     }
}


(index-- is very important here: after splice it will point to the next element, but on the next iteration it will move even further - so you will skip next element in array after splicing it... index-- solves this)

BTW, please use the "code" BB tag when posting code snippets.

ninekorn

#14
wow. it works. ive never used this type of iteration in c#. I didnt knew it even existed in javascript. thank you. I can now move on to getting the containers of the station.

Thanks again! your experience at coding shows. Ok i found the button for quoting scripts.