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

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #15 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:
Code: [Select]
"itemsInCargo = items.GetItemsAndCargo(shop_container_id)".

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

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: Scripting API issue missing a function?
« Reply #16 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.

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: Scripting API issue missing a function?
« Reply #17 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.