Hello,
I have a problem with my Lua code : Label is not "connected" to my frame.
Here's my frame :
[lua]
local TaxiPanel = vgui.Create( "DFrame" )
TaxiPanel:SetSize( 800, 400 )
TaxiPanel:Center()
TaxiPanel:SetTitle( "Window" )
TaxiPanel:MakePopup()
TaxiPanel:ShowCloseButton( true )
TaxiPanel:SetDraggable( false )
TaxiPanel:SetVisible( true )
[/lua]
Here's my button :
[lua]
local button = vgui.Create("DButton" , TaxiPanel)
button:SetPos(590,85)
button:SetSize(200,45)
button:SetText("Centre Ville")
button.DoClick = centreVille
[/lua]
Here's my function :
[lua]
function centreVille()
print("TP Centre Ville")
centreVillePresentation = true
if centreVillePresentation == true then
local label = vgui.Create("DLabel" , TaxiPanel)
label:SetPos( 400, 200 )
label:SetText( "CENTRE VILLE" )
else
end
end
[/lua]
Screenshot of what it does for me : [IMG]http://image.noelshack.com/fichiers/2016/04/1454013922-0145-noelpush.jpeg[/IMG]
Screenshot of what it does for other :[IMG]http://image.noelshack.com/fichiers/2016/04/1454015680-6404-noelpush.png[/IMG]
If someone could help me. :)
Thanks.
[code]
local TaxiPanel = vgui.Create( "DFrame" )
TaxiPanel:SetSize( 800, 400 )
TaxiPanel:Center()
TaxiPanel:SetTitle( "Window" )
TaxiPanel:MakePopup()
TaxiPanel:ShowCloseButton( true )
TaxiPanel:SetDraggable( false )
TaxiPanel:SetVisible( true )
function centreVille()
centreVillePresentation = true
if (centreVillePresentation) then
print("TP Centre Ville")
local label = vgui.Create("DLabel" , TaxiPanel)
label:SetPos( 400, 200 )
label:SetText( "CENTRE VILLE" )
label:SizeToContents()
end
end
local button = vgui.Create("DButton" , TaxiPanel)
button:SetPos(590,85)
button:SetSize(200,45)
button:SetText("Centre Ville")
button.DoClick = centreVille
[/code]
By having a fast look, then it seems like that you're parenting everything right.
If the structure of the code is as posted, then i think that it is better to define the centreVille function before defining it in button.DoClick (As shown in my post). Also just for safety reasons, make sure that you run the code clientside. [URL]https://wiki.garrysmod.com/page/Beginner_Tutorial_Intro[/URL]
Youre trying to use the variable TaxiPanel in a function that youve defined outside the function that creates that vatiable, so youre making it so that it tries to parent it to a nil value beacouse the TaxiPanel variable is not defined there.
Sorry, you need to Log In to post a reply to this thread.