Author Topic: Scripting API issue missing a function?  (Read 363 times)

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Scripting API issue missing a function?
« on: July 19, 2017, 01:29:35 am »
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

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #1 on: July 19, 2017, 01:31:01 am »
items.GetStationShopContainer Id(stationId)
- it should work fine.

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #2 on: July 19, 2017, 01:33:51 am »
thank you!

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #3 on: July 19, 2017, 01:48:32 am »
Does it work properly now?
Why did it not work properly before? I guess you used wrong scope ("station." instead of "items.")?

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #4 on: July 19, 2017, 01:54:53 am »
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

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #5 on: July 19, 2017, 01:57:16 am »
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.GetStationShopContainer Id

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #6 on: July 19, 2017, 02:07:04 am »
wow Notepad++ is powerful. I found itérations of items.GetStationShopContainer Id 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

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #7 on: July 19, 2017, 02:08:55 am »
Sure, I'm glad to help.
There is a good example of this function:
Code: [Select]
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

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #8 on: July 19, 2017, 02:13:10 am »
ok I will definitely look into it

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #9 on: July 19, 2017, 09:17:44 pm »
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.

« Last Edit: July 19, 2017, 09:36:09 pm by ninekorn »

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #10 on: July 19, 2017, 09:43:56 pm »
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

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #11 on: July 19, 2017, 09:48:03 pm »
 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

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #12 on: July 19, 2017, 10:04:39 pm »
 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);         
            }         
         }
         
      }
« Last Edit: July 19, 2017, 10:33:13 pm by ninekorn »

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #13 on: July 19, 2017, 10:39:02 pm »
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:
Code: [Select]
// 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.
« Last Edit: July 19, 2017, 10:43:36 pm by ai_enabled »

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #14 on: July 19, 2017, 10:45:49 pm »
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.
« Last Edit: July 19, 2017, 10:55:30 pm by ninekorn »