5 Replies Latest reply on Dec 1, 2009 1:32 PM by greek_dude247

    Overlay question

    greek_dude247 Level 1

      When I try to overlay instructions in a game I'm creating I get a script error.

       

      So here's some excerpts of the code I'm using right now.

       

       

      When the game begins

       

       

      pIntro = 0

       

      ch = g_world.newtexture("CrossHair", #fromcastmember, member("CrossHair"))
        g_world.camera[1].addoverlay(ch,point(400,300),0)
        ch.renderformat = #rgba8888

       

       

      As the game is running

       

       

      if pIntro = 0 then
          Aa = g_world.newtexture("Intr01", #fromcastmember, member("Intr01"))
          g_world.camera[1].addoverlay(Aa,point(160,340),0)
          Aa.renderformat = #rgba8888
          pIntro = 1
        end if

       

      if pGameTime / 60 = 10 then
          g_world.camera[1].removeOverlay(2)
        end if
       
        if pGameTime / 60 = 12 then
          Bb = g_world.newtexture("Intr02", #fromcastmember, member("Intr02"))
          g_world.camera[1].addoverlay(Bb,point(160,340),0)
          Bb.renderformat = #rgba8888
        end if

       

      So when I try to overlay Bb, I get:

       

      Script error. Object with duplicate name already exists

       

      Bb = g_world.newtexture("Intr02", #fromcastmember, member("Intr02"))

       

      -2147196922

       

      Why am I getting that error? I named the new texture something different.

        • 1. Re: Overlay question
          Sean_Wilson Adobe Community Professional
          So when I try to overlay Bb, I get:

           

          Script error. Object with duplicate name already exists

           

          Bb = g_world.newtexture("Intr02", #fromcastmember, member("Intr02"))

           

          -2147196922

           

          Why am I getting that error? I named the new texture something different.

          It really looks like you already have a texture with that name. I can't suggest how it got there, but I'm inclined to believe the SW3D engine on this point ;-)

          • 2. Re: Overlay question
            multiduck Level 1

            I bet it worked the first time you ran it?   It's a simple problem I have overlooked when creating quick tests, unless you manually or through code reset the w3d, models and textures etc are still going to be there the next time you run your project in Director.

             

            When you initialize your world run member("yourW3D").resetWorld(), this should solve your problem.  3DPI would also help you see what textures etc are in your w3d at any time in your program and can reset or delete certain textures etc without resetting the whole w3d.

             

            Hope this helps.

            • 3. Re: Overlay question
              greek_dude247 Level 1

              First, I should add that the error comes when I try to overlay Intr02 (which is when the game hits 12 seconds).

               

              Second, I've always used the resetWorld code at the initialization for all my levels. I even double checked this level to make sure I didn't make a stupid mistake.

               

              Any other ideas?

              • 4. Re: Overlay question
                multiduck Level 1

                Well according to your error message you never get so far as to create the overlay, the error occurs the line before you assign the texture, there clearly exists an instance of an texture with the same name at the time.

                 

                Also if you ran the program past the texture creation, saved your dir, then director won't remove it on resetworld, but since you checked inside the w3d member in your dir or cst we'll assume it's clean.

                 

                I sugest inserting a break point before or on the line causing the error and either through 3DPI, object inspector or through lingo code in the message window, checking to see if the texture exists.

                 

                Off the top of my head possible causes may be that:

                you are calling this function more than once (pGameTime isn't updated before you reenter this function again?),

                creating a texture with the same name somewhere else (do a search for "Intr02").

                 

                Other than that it's difficult to guess, the only way to be sure would be to step through the movie and see what happens, if you have a stripped down version of your game with the error I'd be willing to take a look.

                • 5. Re: Overlay question
                  greek_dude247 Level 1

                  ok, I'm just thinking out loud right now on the forum but, I think maybe its overlaying it again within the second. You know what I mean? Like...right when 12 seconds hits, it overlays the image but even a millisecond after the 12 marker it tries to overlay again.. I'm gonna try to walk around this somehow and see if it works.