How to check if an object is empty

  • #1, by GingetsuryuuTuesday, 16. April 2013, 18:59 7 years ago
    local object = getObject('Game.GameSavedObject')
    print(tostring(object))
    if object ~= nil then
    getObject('Conditions[Hover item]'):setValue(VConditionValue,false)
    else
    getObject('Conditions[Hover item]'):setValue(VConditionValue,true)
    end
    1
    2
    3
    4
    5
    6
    7
    8


    The code is supposed set the Hover item condition to true if the GameSavedObject is not empty.

    18:52:57: ---Empty---
    18:57:35: Razor (6,14)

    That's the log: The first entry is when GameSavedObject is empty, the second is when the GameSavedObject is set to an object. But regardless of this, the Hover item always returns false.

    Newbie

    9 Posts


  • #2, by afrlmeTuesday, 16. April 2013, 20:00 7 years ago
    ~= nil: is does not equal nil ...
    1
    2


    either set it as == or change the getObject true/false values the other way around.
    currently you have it saying false for when object does not equal nil.

    Imperator

    6805 Posts

  • #3, by GingetsuryuuTuesday, 16. April 2013, 20:04 7 years ago
    I changed it to

    local object = getObject('Game.GameSavedObject')
    if tostring(object) == "---Empty---" then
    getObject('Conditions[Hover item]'):setValue(VConditionValue,false)
    else
    getObject('Conditions[Hover item]'):setValue(VConditionValue,true)
    end
    1
    2
    3
    4
    5
    6
    7


    Which works, but I'm not sure that converting it to string and then comparing it to "---Empty---" is an effective way of doing it.

    Newbie

    9 Posts

  • #4, by afrlmeTuesday, 16. April 2013, 21:07 7 years ago

    Imperator

    6805 Posts

Write post