If Inventory Empty?

  • #20, by JoemcrFriday, 10. February 2017, 15:08 7 years ago
    OK! working now with Lee's most recent effort smile

    and not getting the error anymore.

    Thanks guys!

    Newbie

    96 Posts


  • #21, by JoemcrFriday, 10. February 2017, 15:09 7 years ago
    I'm running 4.2.5

    Newbie

    96 Posts

  • #22, by afrlmeFriday, 10. February 2017, 15:12 7 years ago
    OK! working now with Lee's most recent effort smile

    and not getting the error anymore.

    Thanks guys!
    No problem mate. wink

    I found it amusing that we all came up with different solutions. All of them would have probably worked with a bit of testing & tweaking.

    Imperator

    7278 Posts

  • #23, by ke4Friday, 10. February 2017, 15:15 7 years ago
    @ Lee: Okay thanks for the info mate. I was trying the piece of code i was posting here and it worked for me though. Just checked the Data Structure table and there is no any other field having the Value in it so i suppose it should be fine in this case. ( there are only fields like InterfaceValues, ObjectValues )

    @ Joe: Glad it finally works smile

    Key Killer

    810 Posts

  • #24, by afrlmeFriday, 10. February 2017, 15:38 7 years ago
    @ Lee: Okay thanks for the info mate. I was trying the piece of code i was posting here and it worked for me though. Just checked the Data Structure table and there is no any other field having the Value in it so i suppose it should be fine in this case. ( there are only fields like InterfaceValues, ObjectValues )

    @ Joe: Glad it finally works smile
    I think that's the problem. Don't forget that you could technically type the wrong kind of data structure field into something.
    Values["example"].ConditionValue
    -- or
    Conditions["example"].ValueInt

    & so on. VS doesn't automatically know you are trying to access x based on y data structure field. Why I said it's a bit hit & miss.

    As for value. All the fields under value contain Value in them too. Then you have SceneValues, ObjectValues, CharacterValues & InterfaceValues, whereas for String & Int you only have ValueString & ValueInt as far as I can see in data structure.

    Imperator

    7278 Posts

  • #25, by elecFriday, 10. February 2017, 17:30 7 years ago
    Would it be possible to just set value +/-1 if the character gets an item or loses it
    Then you could just the "If value = 0" ?

    Forum Fan

    109 Posts

  • #26, by afrlmeFriday, 10. February 2017, 17:52 7 years ago
    Would it be possible to just set value +/-1 if the character gets an item or loses it
    Then you could just the "If value = 0" ?
    Issue is actually solved, but yes it's possible, but not much point as you can actually as shown in the final working solution I provided just query the amount of entries in the item table belonging to the active character. tablemaxn(table_name) or #table_name or #(table_name) will return the integer value of the amount of entries belonging to the table. If there are no entries then it will return 0 otherwise it will return the total amount of entries. It's something I often use when I need to iterate through some table with a for loop. 
    local itm = game.CurrentCharacter.CharacterItems -- store current inventory items in a variable
    
    for i = 1, #itm do -- iterate from index value 1 to total amount of items in inventory
     print itm[i]:getName() -- print the name of each item in the inventory
    end

    ... if the value is 0 then the for loop will do nothing because no items exist, though it might generate an error for trying to access an entry in index value 1 - not sure, but could always wrap in an if query to check if #itm >= 1 then...

    Imperator

    7278 Posts