Graphics

 View Only
Expand all | Collapse all

CopyMat Scipting Help "“ Loops

  • 1.  CopyMat Scipting Help "“ Loops

    Posted 06-19-2014 04:16

    Hey All...

    I'm trying to do a fullscreen in XPression for the next days' World Cup games. Some days there are 3 games, and some days there are 4. I want to do this on one scene with an option for 3 games or 4.

    The script I have written works perfectly, copying text data and materials from the 4 game portion to the 3 game portion except for one material that won't copy.

    The script is below. As you can see I have declared the CopyMat as xpBaseObject ... 6 of them, in fact. 2-6 work just fine, but the one that has no number doesn't work no matter what I do. I changed it to CopyMat1, and CopyMat7 just to see, and it just won't copy that material.

    Any help is greatly appreciated! Thanks!

     

    'Team Names and Game Times

    Dim LeftTeam1 as xpTextObject

    Dim RightTeam1 as xpTextObject

    Dim Game1Time as xpTextObject

    Dim LeftTeam2 as xpTextObject

    Dim RightTeam2 as xpTextObject

    Dim Game2Time as xpTextObject

    Dim LeftTeam3 as xpTextObject

    Dim RightTeam3 as xpTextObject

    Dim Game3Time as xpTextObject

    Dim LeftTeam4 as xpTextObject

    Dim RightTeam4 as xpTextObject

    Dim Game4Time as xpTextObject

    Dim ThreeOneLeft as xpTextObject

    Dim ThreeOneRight as xpTextObject

    Dim ThreeOneTime as xpTextObject

    Dim ThreeTwoLeft as xpTextObject

    Dim ThreeTwoRight as xpTextObject

    Dim ThreeTwoTime as xpTextObject

    Dim ThreeThreeLeft as xpTextObject

    Dim ThreeThreeRight as xpTextObject

    Dim ThreeThreeTime as xpTextObject

    'Flags - 4 Games

    Dim LeftTeam1Pic as xpBaseObject

    Dim RightTeam1Pic as xpBaseObject

    Dim LeftTeam2Pic as xpBaseObject

    Dim RightTeam2Pic as xpBaseObject

    Dim LeftTeam3Pic as xpBaseObject

    Dim RightTeam3Pic as xpBaseObject

    ' Flags - 3 Games

    Dim LeftTeamOnePic as xpBaseObject

    Dim RightTeamOnePic as xpBaseObject

    Dim LeftTeamTwoPic as xpBaseObject

    Dim RightTeamTwoPic as xpBaseObject

    Dim LeftTeamThreePic as xpBaseObject

    Dim RightTeamThreePic as xpBaseObject

    ' Flags - CopyMats

    Dim CopyMat as xpMaterial

    Dim CopyMat2 as xpMaterial

    Dim CopyMat3 as xpMaterial

    Dim CopyMat4 as xpMaterial

    Dim CopyMat5 as xpMaterial

    Dim CopyMat6 as xpMaterial

    ' Team Names and Times

    Self.GetObjectByName("Left Team 1", LeftTeam1)

    Self.GetObjectByName("Right Team 1", RightTeam1)

    Self.GetObjectByName("Game 1 Time", Game1Time)

    Self.GetObjectByName("Left Team 2", LeftTeam2)

    Self.GetObjectByName("Right Team 2", RightTeam2)

    Self.GetObjectByName("Game 2 Time", Game2Time)

    Self.GetObjectByName("Left Team 3", LeftTeam3)

    Self.GetObjectByName("Right Team 3", RightTeam3)

    Self.GetObjectByName("Game 3 Time", Game3Time)

    Self.GetObjectByName("31 Left", ThreeOneLeft)

    Self.GetObjectByName("31 Right", ThreeOneRight)

    Self.GetObjectByName("31 Time", ThreeOneTime)

    Self.GetObjectByName("32 Left", ThreeTwoLeft)

    Self.GetObjectByName("32 Right", ThreeTwoRight)

    Self.GetObjectByName("32 Time", ThreeTwoTime)

    Self.GetObjectByName("33 Left", ThreeThreeLeft)

    Self.GetObjectByName("33 Right", ThreeThreeRight)

    Self.GetObjectByName("33 Time", ThreeThreeTime)

    ' Flags - 4 Games

    Self.GetObjectByName("Left Team 1 Flag",LeftTeam1Pic)

    Self.GetObjectByName("Right Team 1 Flag",RightTeam1Pic)

    Self.GetObjectByName("Left Team 2 Flag",LeftTeam2Pic)

    Self.GetObjectByName("Right Team 2 Flag",RightTeam2Pic)

    Self.GetObjectByName("Left Team 3 Flag",LeftTeam3Pic)

    Self.GetObjectByName("Right Team 3 Flag",RightTeam3Pic)

    Self.GetObjectByName("31 Left Flag",LeftTeam1Pic)

    ' Flags - 3 Games

    Self.GetObjectByName("31 Left Flag",LeftTeamOnePic)

    Self.GetObjectByName("31 Right Flag",RightTeamOnePic)

    Self.GetObjectByName("32 Left Flag",LeftTeamTwoPic)

    Self.GetObjectByName("32 Right Flag",RightTeamTwoPic)

    Self.GetObjectByName("33 Left Flag",LeftTeamThreePic)

    Self.GetObjectByName("33 Right Flag",RightTeamThreePic)

    ' Copy Text Game 1

    ThreeOneLeft.Text = LeftTeam1.Text

    ThreeOneRight.Text = RightTeam1.Text

    ThreeOneTime.Text = Game1Time.Text

    ' Copy Text Game 2

    ThreeTwoLeft.Text = LeftTeam2.Text

    ThreeTwoRight.Text = RightTeam2.Text

    ThreeTwoTime.Text = Game2Time.Text

    ' Copy Text Game 3

    ThreeThreeLeft.Text = LeftTeam3.Text

    ThreeThreeRight.Text = RightTeam3.Text

    ThreeThreeTime.Text = Game3Time.Text

    ' Copy Flags Game 1

    LeftTeam1Pic.GetMaterial(0, CopyMat)

    LeftTeamOnePic.SetMaterial(0, CopyMat)

    RightTeam1Pic.GetMaterial(0, CopyMat2)

    RightTeamOnePic.SetMaterial(0, CopyMat2)

    ' Copy Flags Game 2

    LeftTeam2Pic.GetMaterial(0, CopyMat3)

    LeftTeamTwoPic.SetMaterial(0, CopyMat3)

    RightTeam2Pic.GetMaterial(0, CopyMat4)

    RightTeamTwoPic.SetMaterial(0, CopyMat4)

    ' Copy Flags Game 3

    LeftTeam3Pic.GetMaterial(0, CopyMat5)

    LeftTeamThreePic.SetMaterial(0, CopyMat5)

    RightTeam3Pic.GetMaterial(0, CopyMat6)

    RightTeamThreePic.SetMaterial(0, CopyMat6)


  • 2.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-19-2014 11:32
    You do a Getobjectbyname twice for LeftTeam1Pic and overwrite the correct object. Just remove that extra incorrect line at the end of the "flags - 4 games" section.

    #XPression


  • 3.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-19-2014 11:35
    As a tip, you should look into vbscript loops, it could reduce this script to only a few lines. If you need examples let me know.

    #XPression


  • 4.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-19-2014 11:36
    Wow, can't believe I missed that. Thank you! Sometimes it just takes a second pair of eyes.

    Thanks!!

    #XPression


  • 5.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-19-2014 11:38
    I'll definitely take examples of anything regarding scripting.

    Making the scripts shorter has been a goal of mine, but I'm not a programmer.

    #XPression


  • 6.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-19-2014 12:25
    Here is your script written with a loop.

    Note that this requires you to rename your objects to: 4GameTeamL1, 4GameTeamR1, 4GameTeamL2, 4GameTeamR2, etc.. 3GameTeamL1, 3GameTeamR1, etc..

    and the quads would be 4GameTeamPic1, 4GameTeamPic2, etc..



    dim i as integer

    dim txt1 as xpTextObject

    dim txt2 as xpTextObject

    dim pic1 as xpBaseObject

    dim pic2 as xpBaseObject

    dim mat as xpMaterial

    for i = 1 to 3

    Self.GetObjectByName("4GameTeamL" & i , txt1)

    Self.GetObjectByName("3GameTeamL" & i, txt2)

    txt2.Text = txt1.Text

    Self.GetObjectByName("4GameTeamR" & i , txt1)

    Self.GetObjectByName("3GameTeamR" & i, txt2)

    txt2.Text = txt1.Text

    Self.GetObjectByName("4GameTeamPic" & i ,pic1)

    Self.GetObjectByName("3GameTeamPic" & i, pic2)

    pic1.GetMaterial(0, mat)

    pic2.SetMaterial(0, mat)

    next



    #XPression


  • 7.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-24-2014 02:19
    This makes my brain hurt lol.

    I can't even form my question correctly.

    How does it know which pic is copying to which? There's a pic1 and a pic2, but I have 8 flags on the 4 game version, and 6 flags on the 3 game version. And I want to add a 2 game version as well.

    BTW, I tried adding a 2 game version the traditional way and it got all messed up. I need to work on that one some more.

    #XPression


  • 8.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-24-2014 02:26
    It looks like I made a mistake.. I'm only copying 1 picture each time through the loop, but really there should be a pic for the left team and for the right team..

    The key to this working is the & i in the GetObjectByName calls. That appends the loop number (i) to the name of the objects as it runs through the loop each time..

    If you can't get this working; try to post a dropbox link to your scene and I can fix the scripting for you.

    dim i as integer

    dim txt1 as xpTextObject

    dim txt2 as xpTextObject

    dim pic1 as xpBaseObject

    dim pic2 as xpBaseObject

    dim mat as xpMaterial

    for i = 1 to 3

    Self.GetObjectByName("4GameTeamL" & i , txt1)

    Self.GetObjectByName("3GameTeamL" & i, txt2)

    txt2.Text = txt1.Text

    Self.GetObjectByName("4GameTeamR" & i , txt1)

    Self.GetObjectByName("3GameTeamR" & i, txt2)

    txt2.Text = txt1.Text

    Self.GetObjectByName("4GameTeamRightPic" & i ,pic1)

    Self.GetObjectByName("3GameTeamRightPic" & i, pic2)

    pic1.GetMaterial(0, mat)

    pic2.SetMaterial(0, mat)

    Self.GetObjectByName("4GameTeamLeftPic" & i ,pic1)

    Self.GetObjectByName("3GameTeamLeftPic" & i, pic2)

    pic1.GetMaterial(0, mat)

    pic2.SetMaterial(0, mat)

    next



    #XPression


  • 9.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-24-2014 02:42
    OK, thanks... I hadn't even tried it yet, because something didn't look right. I'd have to do the same thing with the game times, but I think I can figure that out.

    Thank you so much... I'll try it as soon as I can. I'm a director here, but I'm also the XPression go-to guy, so I don't always have time to play around.

    Thanks again, and I'll let you know!

    #XPression


  • 10.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-26-2014 03:51
    Worked like a charm! Thank you so much! Now I get to go back and utilize this in other scenes that do the same thing.

    Thanks again!

    #XPression


  • 11.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-28-2014 04:14

    Hey Brian...

    Any ideas on how to do this with a 3rd option of only 2 games?

    I tried some things and got the 2 and 4 games to work, but then the 3 game version was messed up.

    Here's what I tried:

     

    dim i as integer

    dim txt1 as xpTextObject

    dim txt2 as xpTextObject

    dim txt3 as xpTextObject

    dim pic1 as xpBaseObject

    dim pic2 as xpBaseObject

    dim pic3 as xpBaseObject

    dim mat as xpMaterial

    for i = 1 to 3

    Self.GetObjectByName("4GameTeamL" & i , txt1)

    Self.GetObjectByName("3GameTeamL" & i, txt2)

    Self.GetObjectByName("2GameTeamL" & i, txt3)

    txt2.Text = txt1.Text

    txt3.Text = txt1.Text

    Self.GetObjectByName("4GameTeamR" & i , txt1)

    Self.GetObjectByName("3GameTeamR" & i, txt2)

    Self.GetObjectByName("2GameTeamR" & i, txt3)

    txt2.Text = txt1.Text

    txt3.Text = txt1.Text

    Self.GetObjectByName("4GameTeamRightPic" & i ,pic1)

    Self.GetObjectByName("3GameTeamRightPic" & i, pic2)

    Self.GetObjectByName("2GameTeamRightPic" &, pic3)

    pic1.GetMaterial(0, mat)

    pic2.SetMaterial(0, mat)

    pic3.SetMaterial(0, mat)

    Self.GetObjectByName("4GameTeamLeftPic" & i ,pic1)

    Self.GetObjectByName("3GameTeamLeftPic" & i, pic2)

    Self.GetObjectByName("2GameTeamLeftPic" & i, pic3)

    pic1.GetMaterial(0, mat)

    pic2.SetMaterial(0, mat)

    pic3.SetMaterial(0, mat)

    Self.GetObjectByName("4GameTime" & i , txt1)

    Self.GetObjectByName("3GameTime" & i, txt2)

    Self.GetObjectByName("2GameTime" & i, txt3)

    txt2.Text = txt1.Text

    txt3.Text = txt1.Text




    next

    I tried some other things, but this one got me the closest. But, on the 3 game, the pics didn't show up on the third games, and the 3GameTeamR text didn't show up, but the left did.

    Thanks in advance. I'm learning as I go :)


    #XPression


  • 12.  RE: CopyMat Scipting Help "“ Loops

    Posted 06-28-2014 13:13
    That probably fails because on the 3rd time around the loop it will be looking for objects like 2GameTeamR3, 2GameTeamL3 etc.. If you do a GetObjectByName and no object exists by that name, then you try using the object the script will crash and exit immediately. In the newest version of XPression you can configure it to get popup messages about these errors..

    You'll need to change the script a bit.. You can use an if statement to check to see if the GetObjectByName succeeded.. if it didn't don't try to update that text object.

    Each of your sections could be something like this:



    Self.GetObjectByName("4GameTeamL" & i , txt1)

    if Self.GetObjectByName("3GameTeamL" & i, txt2) then txt2.Text = txt1.Text

    if Self.GetObjectByName("2GameTeamL" & i, txt2) then txt2.Text = txt1.Text



    (Note you don't need a "txt3" object, you just re-use "txt2" each time..

    The If..Then stuff has to be on a single line; otherwise you need an "end if" like this:



    Self.GetObjectByName("4GameTeamL" & i , txt1)

    if Self.GetObjectByName("3GameTeamL" & i, txt2) then

    txt2.Text = txt1.Text

    end if

    if Self.GetObjectByName("2GameTeamL" & i, txt2) then

    txt2.Text = txt1.Text

    end if



    Same goes for the picture section.. Use:



    Self.GetObjectByName("4GameTeamLeftPic" & i ,pic1)

    pic1.GetMaterial(0, mat)

    if Self.GetObjectByName("3GameTeamLeftPic" & i, pic2) then pic2.SetMaterial(0, mat)

    if Self.GetObjectByName("2GameTeamLeftPic" & i, pic2) then pic2.SetMaterial(0, mat)



    #XPression


  • 13.  RE: CopyMat Scipting Help "“ Loops

    Posted 07-01-2014 04:21
    You're really good. Thanks so much, worked like a charm!

    #XPression