• Print

Author Topic: Removing a derma object  (Read 5767 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Removing a derma object
« on: December 29, 2014, 11:37:16 am »
Hey I'm working on a small script and part of it is a window that shows a player's playermodel
I've got that part working, but I have a button underneath it that "refreshes" it
Which really just means that it gets the model the player is using again and sets the window to show that

The problem is, when the model switches, the model in the window looks all weird

For example, if the window starts showing the Alyx model
It'll look like this

But when I switched my model, it looked like this


So I was thinking, what if instead of just switching the model it's using, I delete the DModelPanel and create a new one with lua
I was looking through the GMod Wiki and I couldn't find anything that would delete a DModelPanel so that I could recreate it
So I figured I would check here to see if any of you know how I would do it, or if there's another way and I'm just not thinking of it

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Removing a derma object
« Reply #1 on: December 29, 2014, 01:26:32 pm »
when you create it you'll have named it.

name = vgui.Create("blah")

just call name:Remove()

You might want to do a check first though.

if IsValid( name ) then name:Remove() end

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Removing a derma object
« Reply #2 on: December 29, 2014, 02:22:42 pm »
Okay...I edited the file to include that, so now it has

Code: Lua
  1. if IsValid( MyModelPic ) then
  2.         MyModelPic:Remove()
  3.         local MyModelPic = vgui.Create( "DModelPanel", MyModelM )
  4.         MyModelPic:SetPos( 15, 10 )
  5.         MyModelPic:SetSize( 130, 175 )
  6.         MyModelPic:SetModel( LocalPlayer():GetModel() )
  7. else
  8.         LocalPlayer():PrintMessage( HUD_PRINTTALK, "Sorry! That's not a valid object!" )
  9. end

It printed out that message, meaning it isn't valid and I'm not sure why
I'm not too sure what it not being valid means or what would cause that

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2727
  • Karma: 430
    • |G4P| Gman4President
Re: Removing a derma object
« Reply #3 on: December 29, 2014, 08:42:25 pm »
If you're trying to call that after the function it was created in then you may need to make it a global.


How are you creating the object in the first place?

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Removing a derma object
« Reply #4 on: December 30, 2014, 11:28:00 am »
inside if a if (CLIENT) then statement there's a timer

It's automatically run and it's in a timer because I would get weird errors that made no sense without it

Code: Lua
  1. timer.Simple( 5, function()
  2.         local MyModelM = vgui.Create( "DFrame" )
  3.         MyModelM:SetPos( 10, 10 )
  4.         MyModelM:SetSize( 150, 200 )
  5.         MyModelM:SetTitle( "" )
  6.         MyModelM:SetDraggable( false )
  7.         MyModelM:ShowCloseButton( false )
  8.                
  9.         local MyModelPic = vgui.Create( "DModelPanel", MyModelM )
  10.         MyModelPic:SetPos( 15, 10 )
  11.         MyModelPic:SetSize( 130, 175 )
  12.         MyModelPic:SetModel( LocalPlayer():GetModel() )
  13.                
  14.         local MyModelB = vgui.Create ( "DButton", MyModelM )
  15.         MyModelB:SetPos( 30, 180 )
  16.         MyModelB:SetText( "Refresh Model" )
  17.         MyModelB:SetSize( 100, 15 )
  18.         MyModelB.DoClick = function()
  19.                 if IsValid( MyModelPic ) then
  20.                         MyModelPic:Remove()
  21.                         local MyModelPic = vgui.Create( "DModelPanel", MyModelM )
  22.                         MyModelPic:SetPos( 15, 10 )
  23.                         MyModelPic:SetSize( 130, 175 )
  24.                         MyModelPic:SetModel( LocalPlayer():GetModel() )
  25.                 else
  26.                         LocalPlayer():PrintMessage( HUD_PRINTTALK, "Sorry! That's not a valid object!" )
  27.                 end
  28.         end
  29.                
  30.         MyModelM.Paint = function()
  31.                 draw.RoundedBox( 1, 0, 0, 150, 200, Color( 255, 0, 0, 255 ) )
  32.         end
  33.                
  34. end )

  • Print