Lua visibility issues

  • #1, by EinzelkämpferThursday, 02. April 2015, 00:44 5 years ago
    Two more Lua questions by the guy who once delivered some Visionaire scripting examples grin :

    1.
    How do I correctly set the visibility of an object through Lua?

    I understand we have the Property "ObjectVisibility" in the data structure, but it seems I am not smart enough to use it. At first I tried the following:
    obj.Visibility = 0
    1
    2

    This throws an error: Unknown data-field "isibility".

    Then I remembered (from years ago) there were such things as "VValue", so I tried:
    obj.VVisibility = 0
    1
    2

    The error went away, but the visibility did not change, so this was obviously a stupid approach.

    Right now I am going with the following:
    obj.TimeToDestVisibility=1 -- that is almost immediately
    obj.DestVisibility = 0
    1
    2
    3

    This is working properly, but I find it unnecessary as I don't need any fading. And I am eager to find out, how to use "ObjectVisibility" correctly.

    2.
    The second question is not exactly about visibility, but close enough to put it here as well and not start another thread. Is it possible to manipulate the order of objects, so that object A is (partly) covered by object B and moments later – after some Lua magic – appears in front of it?

    Newbie

    81 Posts


  • #2, by afrlmeThursday, 02. April 2015, 00:51 5 years ago
    Do you want to transition the visibility over a period of time or instantly?
    Objects["obj_name"].Visibility = 50
    1
    2

    with tween...
    Objects["obj_name"]:to(3000, {Visibility = 50}, easeQuintOut) -- fade out over 3 seconds with smooth fade towards end (easing is optional)
    1
    2

    ... I think it's correct. Done of the top of my head.

    Imperator

    6842 Posts

  • #3, by EinzelkämpferThursday, 02. April 2015, 01:04 5 years ago
    No, as I said above, I don't need any fading.

    Your first code is not working. I am always struggling with the syntax, but as I understand it, you would have to skip the "Object" part of the property name, for example
    obj.RotationCenter = BLA
    1
    2

    instead of
    obj.ObjectRotationCenter = BLA
    1
    2


    But while this example is working, the visibility thing is not.

    Newbie

    81 Posts

  • #4, by afrlmeThursday, 02. April 2015, 01:14 5 years ago
    Yeah it's just visibility.

    Use the tween version but set the delay to 0.

    Objects["name"]:to(0, {Visibility = 50})
    1
    2


    Dest fields require both DestVisibility & the TimeToDestVisibility fields. Visibility field on its own should be scriptable. It's the field I used in my example.

    V should not be needed for shorthand. By the way it could just be the build you are using that isn't recognizing all the shorthand linking. I don't know how finished shorthand was in the build you are using. I can access pretty much all fields globally & with direct linking through game table & specific tables. It was a bit buggy in earlier versions.

    Imperator

    6842 Posts

  • #5, by EinzelkämpferThursday, 02. April 2015, 01:27 5 years ago
    Good point. I think I shouldn't post publicly about issues with internal builds. That may get people confused.

    I will try the to() notation, but I could go with the DestVisibility for now as well.

    I really appreciate your support. Even more once you find the time to answer my second question, too. grin

    Good night for now.

    Newbie

    81 Posts

  • #6, by afrlmeThursday, 02. April 2015, 02:05 5 years ago
    Are you talking about the z-index (object center) order of objects? You may be able to adjust the object center with the to() function but I don't know if it will work. When I tried adjusting the object center (pre 4.x) it required the scene to be reloaded / restarted for the changes to take effect.

    You could adjust the objects offset, but that will also offset the sprite position too. You might be able to counteract that by creating the image sprite as an animation & then adjusting the animation position with the same value as the offset but with an inversed value. Food for thought. wink

    Imperator

    6842 Posts

  • #7, by EinzelkämpferThursday, 02. April 2015, 19:14 5 years ago
    I have tried the to() notation, and it doesn't work either. As far as I understand it's equal to what I had tried in the first place anway.
    obj.Visibility = 0
    -- ^ this should do the same as...
    obj:to(0, {Visibility = 0})
    -- ^ ...this, but they have only one thing in common: they both don't work
    1
    2
    3
    4
    5


    As to my second question: I don't think adjusting the object center will help, because this is only telling the character whether to walk behind or in front of an object. In my case I have a menu (no characters here) with several objects that get moved around. It is just that I can't make an object "move" in z direction, so that it first appears in front of another object and then (after some user action) behind that same other object. I think you need to change the drawing order to achieve that.

    I already have a workaround for this, but I wanted to know, if there is a possibility I have overlooked, because it could simplify the code.

    Newbie

    81 Posts

  • #8, by afrlmeThursday, 02. April 2015, 19:45 5 years ago
    The menu items all have a z-index of -1, I think? You would probably have to use multiple objects with the same images layered above or below the other objects where you need them to appear.

    Actually the object center also determines which objects should be displayed in front of or behind other objects. I vaguely remember testing it pre 4.x, as I've already mentioned & as far as I can remember it did update after a scene reload. I do however think the multiple object solution & some conditions are probably the better way to go, or you could even use visibility to fade in / out the object sprites.

    In regards to the to() function: what I posted works correctly in the build I'm using.

    You can also use the startObjectTween instead, as I mentioned which should work in all 4.x builds, but as stated, it's a lot more complicated & long-winded to use.

    A workflow function I made before the to() function & shorthand... (add as definition script)
    function setOpacity(obj, val, delay, easing)
    obj = getObject("Game.GameCurrentScene.SceneObjects[" .. obj .. "]")
    if val < 0 then val = 0 elseif val > 100 then val = 100 end
    startObjectTween(obj, VObjectVisibility, obj:getInt(VObjectVisibility), val, delay, easing)
    end
    1
    2
    3
    4
    5
    6

    To use, create an execute a script action...
    setOpacity("object_name", 50, 3000, easeQuintOut) -- set Object_name opacity to 50% over 3 seconds with smooth ending.
    1
    2

    Imperator

    6842 Posts

  • #9, by EinzelkämpferFriday, 03. April 2015, 16:01 5 years ago
    Yes, I have used multiple objects on top of each other. That was the workaround I mentioned above.

    As to the visibility: I assume my problem was that I tried to set the visibility of an object before I switched to the scene the object is on. The DestVisibility property works however and I'll keep it, because the puzzle I was creating is complete and running perfectly. So I won't touch the code again unless it turns out to be buggy.

    Thanks for your help.

    Newbie

    81 Posts

  • #10, by afrlmeFriday, 03. April 2015, 16:05 5 years ago
    No problem. smile

    P.S: I just updated the function code block in my message above as it didn't paste in the end below the function for some reason.

    Visibility should be allowed to be set regardless of whether or not you are on the scene. Although the startObjectTween function in my last message is just for current scene. Was done like that so that it only accessed objects from current scene with direct linking as it is safer than global access method.

    Imperator

    6842 Posts

Write post