How to check if an object is empty

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

    Bažant

    9 Posts


  • #2, z afrlmeTuesday, 16. April 2013, 20:00 hodinky 12 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.

    Imperátor

    7285 Posts

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

    Bažant

    9 Posts

  • #4, z afrlmeTuesday, 16. April 2013, 21:07 hodinky 12 years ago

    Imperátor

    7285 Posts