If Inventory Empty?

  • #1, z JoemcrFriday, 10. February 2017, 12:00 hodinky 8 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...

    Bažant

    96 Posts


  • #2, z sebastianFriday, 10. February 2017, 12:08 hodinky 8 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>
     

    Kapitán

    2346 Posts

  • #3, z JoemcrFriday, 10. February 2017, 12:13 hodinky 8 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

    Bažant

    96 Posts

  • #4, z afrlmeFriday, 10. February 2017, 12:30 hodinky 8 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>
     
    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


    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?

    Imperátor

    7285 Posts

  • #5, z JoemcrFriday, 10. February 2017, 13:08 hodinky 8 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...

    Bažant

    96 Posts

  • #6, z afrlmeFriday, 10. February 2017, 13:27 hodinky 8 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()

    & 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.

    Imperátor

    7285 Posts

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


    Kapitán

    2346 Posts

  • #8, z JoemcrFriday, 10. February 2017, 13:56 hodinky 8 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...

    Bažant

    96 Posts

  • #9, z sebastianFriday, 10. February 2017, 14:21 hodinky 8 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

    Kapitán

    2346 Posts

  • #10, z ke4Friday, 10. February 2017, 14:28 hodinky 8 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

    Zabiják klíčů

    810 Posts

  • #11, z JoemcrFriday, 10. February 2017, 14:43 hodinky 8 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...


    Bažant

    96 Posts