If Inventory Empty?

  • #1, by JoemcrFriday, 10. February 2017, 12:00 3 years ago
    Is there an easy way to replicate an 'if inventory = empty' action part? I want to perform a certain action only if the main character is holding no items...

    Newbie

    96 Posts


  • #2, by sebastianFriday, 10. February 2017, 12:08 3 years ago
    in lua you could try

     </div><div><span>char = game:getLink(VGameCurrentCharacter)</span></div><div><span>items = char:getLinks(VCharacterItems)</span></div><div><span>if items == nil then</span></div><div>... </div><div>end</div><div>
    1
     

    Thread Captain

    2337 Posts

  • #3, by JoemcrFriday, 10. February 2017, 12:13 3 years ago
    Thanks Sebastian.

    How could I use this as part of a string of action parts? Use it to set an InventoryEmpty variable or something?
    Sorry, I'm not lua literate :S

    Newbie

    96 Posts

  • #4, by afrlmeFriday, 10. February 2017, 12:30 3 years ago
    in lua you could try

     </div><div><span>char = game:getLink(VGameCurrentCharacter)</span></div><div><span>items = char:getLinks(VCharacterItems)</span></div><div><span>if items == nil then</span></div><div>... </div><div>end</div><div>
    1
     
    What's going on with the code block? Seems to be full of html elements.

    @ Sebastian: There is actually an isEmpty() function.

    function invEmpty()
     if game.CurrentCharacter.CharacterItems:isEmpty() then
      Conditions["inventory_empty"].ConditionValue = true
     else
      Conditions["inventory_empty"].ConditionValue = false
     end
    end
    1
    2
    3
    4
    5
    6
    7


    Create this (above) as a definition script. Create a condition called inventory_empty. Now you could either have it check this in a loop constantly or you could run this function manually by calling it each time you execute an action part that causes an item to be added or removed from the inventory.

    What are you needing this for, if you don't mind my asking?

    Imperator

    6842 Posts

  • #5, by JoemcrFriday, 10. February 2017, 13:08 3 years ago
    Can't seem to get this to work Lee. It doesn't seem to be setting the condition... Does it matter where I create the condition (I put it on the main character).

    I tried 

    Remove all items > call script(yours) > If "inventory_empty" = true > do a thing

    This didn't work either... Any ideas?

    I have a character I can give things to. I want to display some text ('that's all of it' or something) after giving the last item...

    Newbie

    96 Posts

  • #6, by afrlmeFriday, 10. February 2017, 13:27 3 years ago
    What I shared was a function which should be included in a definition script. To execute the script you would need to use an execute a script action containining...
    invEmpty()
    1

    & no, it doesn't matter where you create the condition.

    Quick question: will it be performing the same action each time? Because you could just have it do said actions inside of the function rather than bothering with the condition.

    Imperator

    6842 Posts

  • #7, by sebastianFriday, 10. February 2017, 13:50 3 years ago
    yeah, Lee solution is way better here smile 


    Thread Captain

    2337 Posts

  • #8, by JoemcrFriday, 10. February 2017, 13:56 3 years ago
    Still can't get it to work roll

    Here's a pic of the relevant bits, hopefully I'm doing something dumb...

    I need the condition so I can make reference to it later on...

    Newbie

    96 Posts

  • #9, by sebastianFriday, 10. February 2017, 14:21 3 years ago
    does a Vs condition "inventory_empty"  exist anywhere?. also you set the condition true in any case...

    edit: of course you have... you used it in the action part below the execution script.... 


    ...



    XD

    Thread Captain

    2337 Posts

  • #10, by ke4Friday, 10. February 2017, 14:28 3 years ago
    I've just tried that and for some reason it gives me error because of the isEmpty() function

    You can try this instead:

    function invEmpty()
        if next(game.CurrentCharacter.Items) == nil then
            Conditions["inventory_empty"].Value = true
        else
            Conditions["inventory_empty"].Value = false
        end
    end
    1
    2
    3
    4
    5
    6
    7

    Key Killer

    810 Posts

  • #11, by JoemcrFriday, 10. February 2017, 14:43 3 years ago
    @Sebastian Yes inventory_empty is a condition linked to the main character

    I set it to true/true just to see if it was running and it still didn't cange the condition to true...

    @ke4 this doesn't seem to do the job either...


    Newbie

    96 Posts

Write post