AtomicTorch Studio Forums

VoidExpanse => Modding info => Topic started by: ninekorn on July 19, 2017, 01:29:35 AM

Title: Scripting API issue missing a function?
Post by: ninekorn 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
Title: Re: Scripting API issue missing a function?
Post by: ai_enabled on July 19, 2017, 01:31:01 AM
items.GetStationShopContainerId(stationId)
- it should work fine.
Title: Re: Scripting API issue missing a function?
Post by: ninekorn on July 19, 2017, 01:33:51 AM
thank you!
Title: Re: Scripting API issue missing a function?
Post by: ai_enabled 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.")?
Title: Re: Scripting API issue missing a function?
Post by: ninekorn 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
Title: Re: Scripting API issue missing a function?
Post by: ai_enabled 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.GetStationShopContainerId
Title: Re: Scripting API issue missing a function?
Post by: ninekorn on July 19, 2017, 02:07:04 AM
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
Title: Re: Scripting API issue missing a function?
Post by: ai_enabled on July 19, 2017, 02:08:55 AM
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).
Title: Re: Scripting API issue missing a function?
Post by: ninekorn on July 19, 2017, 02:13:10 AM
ok I will definitely look into it
Title: Re: Scripting API issue missing a function?
Post by: ninekorn 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.

Title: Re: Scripting API issue missing a function?
Post by: ai_enabled 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.
Title: Re: Scripting API issue missing a function?
Post by: ninekorn 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.
Title: Re: Scripting API issue missing a function?
Post by: ninekorn 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);         
            }         
         }
         
      }
Title: Re: Scripting API issue missing a function?
Post by: ai_enabled 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:

// 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.
Title: Re: Scripting API issue missing a function?
Post by: ninekorn 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.
Title: Re: Scripting API issue missing a function?
Post by: ninekorn on July 20, 2017, 01:45:39 AM
Hey AI-Enable. If youre still working could I know how to access items from "itemsInCargo = items.GetItemsAndCargo(shop_container_id)". This gives me an array of objects. but nowhere i can find in the scripts how to go get the difference shop sections like "boosters" "devices" "hulls" etc. When I write a for loop to try and get them i get [object object] and when i do a double for loop to iterate through itemsInCargo[g] I get nothing. again. thats probably my lack of knowledge of javascript but still theres no explanation for that in the Scripting API unless I just didnt find it. You see Im creating this market Terminal where players will be able to access every shops in each system the moment they access that terminal. Right now I can select systems then stations then I get the "main" station container i guess then I thought I would get the different sections of the shops with that GetItemsAndCargo function. But it just returns "object object" all the time. Once I get those items I will incorporate buy/sell for the player to buy items from the other side of the galaxy. Im not there yet.

something like:

"itemsInCargo = items.GetItemsAndCargo(shop_container_id)".

for (i = 0; i < itemsInCargo.length; i++)
{
       console.Print(itemsInCargo[i]+ " " + " SHOPCONTAINERID");
}
then i dont know what?

Title: Re: Scripting API issue missing a function?
Post by: ai_enabled on July 20, 2017, 01:52:14 AM
There are no actual sections in the shop container - it simply contains items list. The sections are working as a simple filter on the client-side only - it knows all the items in the shop container but displays only those which belong to a selected section.
GetItemsAndCargo returns array of objects. Each object contains following fields:
int item_id
int quantity
string xml_id

Beware that cargo items are not usual items - they don't have ID's (always zero) - only xml_id and quantity. But that also helps to determine if item is cargo - just check if item_id == 0.
Title: Re: Scripting API issue missing a function?
Post by: ninekorn on July 20, 2017, 05:35:26 AM
thank you. in the end i was the one that had gone to sleep. had a big day yesterday. Ill try that out today.