gordonramp Posted May 28, 2010 Share Posted May 28, 2010 Hi, I'm hoping someone can help me with this.. Basically, I want to be able to show and hide an object in front of the camera. It's actually showing the object fine with the keyhit but I'm unable to hide it again. The object is parented to the camera and so moves around nicely in full view. How can I hide, delete or shift the object from view. This code resides in the Main Loop of my program. Thanks. if KeyHit(KEY_F5)==1 then if showthing==0 then local object=0.6 local vwep = LoadMesh("abstract::object1.gmf") LoadMesh("abstract::object1",vwep) vwep:SetParent(fw.main.camera,0) vwep:SetPosition(Vec3(-0.0*object,-0.01*object,0.45*object),0) showthing=1 else showthing=0 end end Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
macklebee Posted May 28, 2010 Share Posted May 28, 2010 I wouldn't load the mesh in the main loop but in the initial setup. Why are you loading the mesh twice? Is it "vwep" that you are trying to hide/show? if so just do: vwep:Hide() and vwep:Show() toggled by if the variable showthing is equal to 0 or 1. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Author Share Posted May 28, 2010 Ahh, well I adapted this bit of code from the FPS gun script that comes with the SDK. I agree, I don't want to load the object twice but it seems to be the only way I can get it to show. I'll play around with your suggestions. I'm actually trying to show and hide object1. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Author Share Posted May 28, 2010 This is a little more tidy...loading the object once. But I haven't got the vwep:Hide() and vwep:Show() working.. if KeyHit(KEY_F5)==1 then if showthing==0 then local object=0.6 local vwep = LoadMesh("abstract::object1.gmf") vwep:SetParent(fw.main.camera,0) vwep:SetPosition(Vec3(-0.0*object,-0.01*object,0.45*object),0) showthing=1 else showthing=0 end end Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Author Share Posted May 28, 2010 This gives an error on the second toggle saying 'attempt to index global value 'vwep' a nill value'. It comes from the vwep:Hide() line. The object is appearing but still not disappearing. Can anyone see why? if KeyHit(KEY_F5)==1 then if showthing==0 then local object=0.6 local vwep = LoadMesh("abstract::object1.gmf") vwep:SetParent(fw.main.camera,0) vwep:SetPosition(Vec3(-0.0*object,-0.01*object,0.45*object),0) vwep:Show() showthing=1 else vwep:Hide() showthing=0 end end Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
ZioRed Posted May 28, 2010 Share Posted May 28, 2010 You should declare the variable before the Main loop else it is not visible in the "else" code: local vwep = LoadMesh("abstract::object1.gmf") # ...begin main loop if KeyHit(KEY_F5)==1 then if showthing==0 then local object=0.6 vwep:SetParent(fw.main.camera,0) vwep:SetPosition(Vec3(-0.0*object,-0.01*object,0.45*object),0) vwep:Show() showthing=1 else vwep:Hide() showthing=0 end end # ...end main loop Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Author Share Posted May 28, 2010 Hi ZioRed, Thanks and when I do that the error of course disappears but not the object so I must have something amiss in the variable. I tried the below as well but the object does not toggle on and off. Perhaps it is not possible to hide an object when it is parented. local vwep = LoadMesh("abstract::object1.gmf") --inloop-------------------------------------- if KeyHit(KEY_F5)==1 then if showthing==0 then local object=0.6 vwep:SetParent(fw.main.camera,0) vwep:SetPosition(Vec3(-0.0*object,-0.01*object,0.45*object),0) showthing=1 vwep:Show() else showthing=0 vwep:Hide() end end Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
ZioRed Posted May 28, 2010 Share Posted May 28, 2010 It works with parenting too, the following test works: require("Scripts/constants/keycodes") --Register abstract path RegisterAbstractPath("") --Set graphics mode if Graphics(1024,768)==0 then Notify("Failed to set graphics mode.",1) return end world=CreateWorld() if world==nil then Notify("Failed to initialize engine.",1) return end gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),1+2+4+8) camera=CreateCamera() camera:SetPosition(Vec3(0,0,-2)) mesh_parent = CreateCube() mesh_parent:SetColor(Vec4(0,0,1,1)) mesh_parent:Move(Vec3(0.5,0,0)) mesh=CreateCube() mesh:SetParent(mesh_parent) mesh:Move(Vec3(-1,0,0)) light=CreateDirectionalLight() light:SetRotation(Vec3(45,45,45)) while AppTerminate()==0 do if KeyHit(KEY_ESCAPE)==1 then break end if KeyHit(KEY_F5) == 1 then if EntityHidden(mesh) == 1 then mesh:Show() else mesh:Hide() end end UpdateAppTime() world:Update(AppSpeed()) SetBuffer(gbuffer) world:Render() SetBuffer(BackBuffer()) world:RenderLights(gbuffer) Flip(0) end Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
gordonramp Posted May 28, 2010 Author Share Posted May 28, 2010 ZioRed, Nice that works and I'm sure I can adapt it to my specific needs. Thankyou. Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64. Link to comment Share on other sites More sharing options...
ZioRed Posted May 28, 2010 Share Posted May 28, 2010 No problem, we're here to help each others Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.