Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

If Inventory Empty?

  • #10, by Joemcr 9 years ago Zitieren
    @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...


  • #11, by afrlme 9 years ago Zitieren
    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.
  • #12, by ke4 9 years ago Zitieren
    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.
  • #13, by afrlme 9 years ago Zitieren
    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.
  • #14, by Joemcr 9 years ago Zitieren
    I'm getting the following error in messages.log

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

    don't know if that's related?
  • #15, by ke4 9 years ago Zitieren
    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)
  • #16, by afrlme 9 years ago Zitieren
    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.

  • #17, by afrlme 9 years ago Zitieren
    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.
  • #18, by ke4 9 years ago Zitieren
    You should always use .ConditionValue when accessing/editing conditions with Lua script. 

    Why? The condition holds only true/false information, no? Nothing else.
  • #19, by afrlme 9 years ago Zitieren
    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.
  • #20, by Joemcr 9 years ago Zitieren
    OK! working now with Lee's most recent effort smile

    and not getting the error anymore.

    Thanks guys!