License from €75 Log in
DE EN FR ES IT CZ

How to check if an object is empty

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 14 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.
  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 14 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.
  4. · 14 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.
  5. · 14 years ago

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?