Graphics

 View Only
  • 1.  Script for onSetText event to get previous value of text

    Posted 01-24-2023 09:18
    Hi all. I got a basketball project I'm working on. I'm trying to make a shot clock animate above my score graphic, BUT only when the shot clock goes below 11. I also want it to animate out when shot clock is >= 11. Anyway, the issue I'm having is that EVERY TIME the text changes it animates in or out, but I only want it to animate in when the value changes from 11 or greater to 10 or less, and only animate out only when the value changes from 10 or less to 11 or greater. SO I think I need a way to find the previous value of the text before it changes with the onSetText event. Any thoughts? Thanks.

    ------------------------------
    Roger Heyward
    ------------------------------


  • 2.  RE: Script for onSetText event to get previous value of text

    Posted 01-24-2023 09:54
    This probably isn't the best way but it came to mind. 

    I'm sure there's a better way to write this but I have my head deep in something else atm. 

    dim sd as xpSceneDirector

    dim old as xpTextObject
    scene.GetObjectByName("oldText", old)

    if old.text > 11
    if text < 11
    scene.getscenedirectornyname("In", sd)
    sd.play
    end if
    end if

    if old.text < 11
    if text > 11
    scene.getscenedirectornyname("Out", sd)
    sd.play
    end if
    end if

    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 3.  RE: Script for onSetText event to get previous value of text

    Posted 01-24-2023 12:01
    Thanks Red. I'm new to scripting in Xpression and Visual Basic, so never thought to use a dummy text object to hold my previous values. Question: Do I have to update old after each text change? Seems that I do. So I'd think you need this line at the end of the code:

    old.Text = Text

    ------------------------------
    Roger Heyward
    ------------------------------



  • 4.  RE: Script for onSetText event to get previous value of text

    Posted 01-24-2023 12:04
    Yes, you would want that at the end, I thought I'd written that but must not have copied it from my other window.

    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 5.  RE: Script for onSetText event to get previous value of text

    Posted 01-26-2023 12:06

    Hey Red. I basically got this working. Thanks for the help, but I got one more issue here. Maybe you can help. The project is complex so it is a little hard to explain, so I have attached the project here, https://drive.google.com/file/d/1wYu6SX3aSY8Xr9W2bCJJDLc9hg0kE0gq/view?usp=sharing . You can easily see the problem by taking Item 4053, then change the Shotclock1 text to anything below 11, BUT  the issue is when you take out the score (item 4053). It does weird things. It will disappear then reappear before it dropped down. Basically, I want the shot clock to move down first if it is live. I think it does this sometimes too when you bring the score in. I do have another script running in the Score Out scene director that can also take the shot clock out. Maybe that is the issue. If you can please take a look. Thanks.



    ------------------------------
    Roger Heyward
    ------------------------------



  • 6.  RE: Script for onSetText event to get previous value of text

    Posted 02-23-2023 15:11
      |   view attached

    Sorry. I think my last upload didn't work. 

    Anyway, I got everything working. I ended up changing quite a bit. I just wanted to update this post, so the solution is available on the forum. I simplified the project, so the only scene and take item is the Scoreboard graphic. I also made widgets, GameClock, ShotClock, and ShotClockZeroTimers to feed the data instead of my Datalinq seriel input. 

    Here is how it works:

    1) I added scripts into all of the scene directors to indicate the state of what was changing, such as the ScoreIn scene director starts with a script that changes a text object, ScoreboardState = "In". Then when the animation completes it becomes Scoreboard = "On". In the same way I did Out and Off for the ScoreOut scene director. Basically, I use "In" as programming flags to mean it is animating in, "Out" as a flag for it is animating out, "On" as a flag for the graphic is visible and "Off" as a flag for the graphic is no longer visible. I also did this for the shot clock scene directors ShotClockIn and ShotClockOut and updated a text object called ShotClockState.

    2) Then I use the OnSetText for the text object ShotClockHidden to run a script that checks the ScoreboardState, ShotClockState, and the the previous value of the shot clock to the present value. This allows me to decide what needs to happen, such as if the shot clock value has changed from > 10 to <= 10 then animate up the shot clock or if the situation is the reverse and shot clock value changes from <= 10 to > 10 then animate the shot clock out. There are a few more scenarios, that change the font color, check for erroneous states and if the shot clock is On after the value has been zero for too long, but that is the basics. You can see all of the code in the attached file of the project.

    3) Finally, the last situation is how I had to animate out the shot clock if the shot clock was On when the scoreboard was triggered to animate off. What I did here is add a script into the ScoreOut scene director that checks for the state of the shot clock. If the state is On then I trigger the ShotClockOut scene director and then I added 15 frames (the length of the ShotClockOut  scene director animation) before I animate out the Scoreboard. There is one rare situation I can see that could happened to cause problems. That is what if the Scoreboard is triggered to go out while the shot clock is in the In state. That would mean that the shot clock would be in the middle of its animation. I think I could have added an extra flag for this and added an extra script that checked for this to start the ShotClockOut just a bit later, but honestly I'm not that concerned about it. Anyway, thanks to everyone who helped here on this forum. Ross community is the best. 



    ------------------------------
    Roger Heyward
    ------------------------------

    Attachment(s)

    xpp
    SportsPractice.xpp   1.20 MB 1 version