Graphics

 View Only
  • 1.  Basic scripting help - show/hide object based on datalinq value

    Posted 06-12-2013 23:45
    Hi there. I'm fairly new to Xpression and am having a heck of a time trying to learn how to do some basic scripting (especially with the lack of examples/documentation).

    I have a hidden datalinq text object that automatically updates with a value of 0 or 1. If it's 1, I want to make a separate image object visible, if the value is 0, the object should be hidden.

    This is the code I'm trying, in OnSetText...

    if Text = 1 then

    Scene.SampleObject.visible = true

    else

    Scene.SampleObject.visible = false

    end if



    Any help would be appreciated! Thanks.


  • 2.  RE: Basic scripting help - show/hide object based on datalinq value

    Posted 06-13-2013 15:25
    First, I would do this at the scene level. I've just had better results. Then I would run it at the OnOnline, OnRender, and onPreviewRender. Since you're not just dealing with text, but with object visibility.

    Then try this code:

    dim txt as xpTextObject

    dim obj as xpBaseObject

    self.GetObjectByName("Your Text Object's Name", txt)

    self.GetObjectByName("Your Object's Name", obj)

    if txt.text = 1 then

    obj.visible = true

    elseif txt.text = 0 then

    obj.visible = false

    end if


    Since your values are known, you should specify by using elseif instead of else. If your text could be anything, but only if it was "1" you wanted something visible, then I would say to do that the other way.

    Another method I've had success with is using InStr, or "In String." This function returns the number of characters within $A that $B falls at. For example, if

    $A=abcdefg

    InStr($A, "b") would return 2

    InStr($A, "d") would return 4

    etc...


    I would use this:

    if InStr(txt.Text, "1") = 1 then

    obj.visible = True

    else

    obj.visible = False

    end if


    That would say "if the first character in your text is 1, then make it visible, otherwise hide it."

    #XPression


  • 3.  RE: Basic scripting help - show/hide object based on datalinq value

    Posted 06-13-2013 17:26
    Thanks Dan... that'll put me in the right direction.

    #XPression


  • 4.  RE: Basic scripting help - show/hide object based on datalinq value

    Posted 06-13-2013 20:18
    In addition to all the comments Dan made, I don't think you can do "if txt.text = 1".. you probably need the 1 in quotation marks like if txt.text = "1" because you are trying to compare two strings..

    #XPression


  • 5.  RE: Basic scripting help - show/hide object based on datalinq value

    Posted 06-13-2013 21:05
    Thanks. The code above worked perfectly. Curiously it did indeed work without having to put the value in quotation marks.

    #XPression


  • 6.  RE: Basic scripting help - show/hide object based on datalinq value

    Posted 06-13-2013 21:07
    It worked because it saw "1" as a string since we were comparing it to a .Text. If we were comparing to to an integer, it would have been confused, as it would have been going up against a string. This is just comparing two strings to each other to see if they are the same.

    #XPression