1 Reply Latest reply on Dec 1, 2006 2:53 AM by duckets

    Light in 3D game

    sprackles Level 1
      I have the following code written in a behaiour to change lights, I have a light already in my 3D file and this behaviour is designed to change the light:
      property p3Dmember -- reference to 3D cast member
      property pCharacter -- reference to the character in the 3D world
      property pLight


      on beginSprite me

      -- initiate properties and 3D world
      p3Dmember = sprite(me.spriteNum).member


      comLight

      pLight=1
      end

      on comLight
      if voidP(p3Dmember.light("Bulb Light")) then
      -- set new light
      p3Dmember.newLight("Bulb Light", #point)

      -- set colour and intensity
      p3Dmember.light("Bulb Light").color = rgb(255,255,255)

      -- p3Dmember.light("Bulb Light").specular = 1
      p3Dmember.light("Bulb Light").specular = 0

      -- move light position
      p3Dmember.light("Bulb Light").transform.position = vector(0,0,100)
      p3Dmember.light("Bulb Light").removefromworld()
      end if

      end



      on lightChange
      p3Dmember.light(pLight).removefromworld()
      if (pLight<p3DMember.light.Count) then
      pLight=pLight+1
      else
      pLight=1
      end if
      p3Dmember.light(pLight).addtoworld()
      end



      on keypress
      if keypressed("l") then lightChange
      end


      I don't see why this shouldn't work, but I keep getting an error message saying:
      if voidP(p3Dmember.light("Bulb Light")) then

      #light

      Can anybody help?!?!?
        • 1. Re: Light in 3D game
          duckets Level 1

          You need to declare 'p3Dmember' as a property at the top of your behaviour, like this:

          property p3Dmember

          Otherwise the variable's scope is only within the handler it is used, and is forgotton when the handler reaches its 'end'.

          - Ben