How to check if an object is empty

  • #1, by GingetsuryuuTuesday, 16. April 2013, 18:59 11 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
    


    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 11 years ago
    ~= nil: is does not equal nil ...
    


    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

    7278 Posts

  • #3, by GingetsuryuuTuesday, 16. April 2013, 20:04 11 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
    


    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 11 years ago

    Imperator

    7278 Posts