question

walldiv avatar image
walldiv asked

For Loop - Iterating GetCharacterInventory & matching

Hello! I am trying to do the following iteration on server.GetCharacterInventory() and I am straight up no table to successfully operand the if statement..... however i've debugged out my incoming ItemId as well the ItemId i would expect to find in the for loop... and they match in a different revision that has the output of both mentioned - but this chunk of code wont do that for me.... what am I doing wrong?

var StringMatched = "not found";
  
  for (var i = 0; i < RetInv.Inventory.Length; i++)  //iterate returned inventory, find itemids matching
  {
    if(RetInv.Inventory[i].ItemId == PerkID)
    {
      StringMatched = "found item!";
      break;
    }
  }
  
  log.debug(request);
  return {IncomingPerkID: PerkID, CharacterInventory: RetInv.Inventory[0].ItemId};
  //return {messageValue: StringMatched};
CloudScript
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JayZuo avatar image
JayZuo answered

The code you've posted seems right. The only problem I can find is that you should use "RetInv.Inventory.length" instead of "RetInv.Inventory.Length". I'm not sure if this is a typo, but length property is what we used in JavaScript. Besides this, you may also log all the Inventory returned by server.GetCharacterInventory() to see if there indeed has the "PerkID".

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

walldiv avatar image walldiv commented ·

That indeed was it.... crazy that the lowercase L in Length is what killed this......

Thanks for the fix!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.