If Inventory Empty?

  • #10, 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


  • #11, z afrlmeFriday, 10. February 2017, 14:45 hodinky 8 years ago
    Maybe it doesn't like that I used .CharacterItems instead of .Items? or maybe inventory never equals empty because it's a table containing multiple entries rather than a single field. I know that, for example...
    if game.SpeechLanguage:isEmpty() then

    works, but you can also use nil in most cases too. I think isEmpty() was supposed to be a time saver so you don't have to type out blah blah blah == nil / ~= nil, etc.

    @ Ke4: why is there a "next" in your script?

    @ Joe: you will probably need to add a short pause action part between running the execute a script & checking the condition. Say 50-100ms or so. Alternatively you could create the display text inside of a called by other action & just have the function start that action rather than relying on the condition.

    Imperátor

    7285 Posts

  • #12, z ke4Friday, 10. February 2017, 14:46 hodinky 8 years ago
    Weird, works for me. Do you have any errors in the messages.log file?

    @ Lee: Not sure if i'm correct but checking a table against nil will always return false. You want to check for any entries in the table itself.

    At least it was giving me false everytime without the next function.

    Zabiják klíčů

    810 Posts

  • #13, z afrlmeFriday, 10. February 2017, 14:51 hodinky 8 years ago
    By the way you could also check the total inventory count too...
    if #(game.CurrentCharacter.CharacterItems) == 0 then

    ... it should work. Basically we are checking the total amount of entries in the table, but I'm not sure off the top of my head if it would return 0 or nil. Need to check.

    Ok checked. This works fine for me.
    function invEmpty()
     --print("the current character contains " .. #game.CurrentCharacter.CharacterItems .. " items in their inventory")
     if #(game.CurrentCharacter.CharacterItems) == 0 then
      startAction(Actions["no_items"])
     end
    end

    I create a called by other action which I called no_items & added a display text to it. The function checks if table entries equals 0 & if it does then it calls the no_items action.

    P.S: tested adding an item to inventory too. My print line which I commented out in the script says I have 1 item & didn't call the called by other action that triggers the display text.

    Imperátor

    7285 Posts

  • #14, z JoemcrFriday, 10. February 2017, 14:58 hodinky 8 years ago
    I'm getting the following error in messages.log

    13:55:37: Error: Unknown data-field "alue".

    don't know if that's related?

    Bažant

    96 Posts

  • #15, z ke4Friday, 10. February 2017, 15:00 hodinky 8 years ago
    What version of Visonaire are you using? You can try changing the .Value to .ConditionValue after the Conditions["inventory_empty"]

    You could also try the old method like

    getObject("Conditions[inventory_empty]"):setValue(VConditionValue, true)

    Zabiják klíčů

    810 Posts

  • #16, z afrlmeFriday, 10. February 2017, 15:01 hodinky 8 years ago
    I'm getting the following error in messages.log

    13:55:37: Error: Unknown data-field "alue".

    don't know if that's related?
    Yes, it means it's probably not finding a condition or value. Maybe duplication issue or searching for a condition or value that no longer exists. Check out the new script/method I just shared with you in my post above.

    Imperátor

    7285 Posts

  • #17, z afrlmeFriday, 10. February 2017, 15:02 hodinky 8 years ago
    What version of Visonaire are you using? You can try changie the .Value to .ConditionValue after the Conditions["inventory_empty"]

    You could also try the old method like

    getObject("Conditions[inventory_empty]"):setValue(VConditionValue, true)
    You should always use .ConditionValue when accessing/editing conditions with Lua script.

    Imperátor

    7285 Posts

  • #18, z ke4Friday, 10. February 2017, 15:04 hodinky 8 years ago
    You should always use .ConditionValue when accessing/editing conditions with Lua script. 

    Why? The condition holds only true/false information, no? Nothing else.

    Zabiják klíčů

    810 Posts

  • #19, z afrlmeFriday, 10. February 2017, 15:08 hodinky 8 years ago
    You should always use .ConditionValue when accessing/editing conditions with Lua script. 

    Why? The condition holds only true/false information, no? Nothing else.
    Because other data structure fields contain the word Value in them so it could confuse the engine. Shorthand is very hit & miss at times. Don't forget that we have .ValueString & .ValueInt, but we only use .Int & .String to access/edit those, but condition field is .ConditionValue for some reason rather than ValueCondition. Ideally it would have been nice if we could just use .Int, .Str, .Cond - which is something Simon could probably sort out, but the data structure is already confusing enough as it is due to the multiple methods available of accessing & editing the data.

    P.S: you may have noticed the examples I provided like int & string are the final words in the field, whereas the important word in the condition field is not at the end, yet you can't simply type .Condition because a word exists after it - it will likely log an error.

    Imperátor

    7285 Posts

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

    and not getting the error anymore.

    Thanks guys!

    Bažant

    96 Posts