I created a Panel with Vgui Custom but when I test the Panel I have the text writed in half, weird.
and also I have an error with the line 34 in my text editor but not in gmod : the error is the ||
Some one have an idea why ?
[IMG]http://img5.imageshack.us/img5/2610/halftext.jpg[/IMG]
[lua]
cLabel = {};
cLabel.Text = nil;
cLabel.TextAlign = nil;
cLabel.Font = nil;
cLabel.Color = nil;
function cLabel:Init()
self.Text ="";
self.TextAlign = 0;
self.Font = "ScoreboardText";
self.Color = Color( 255,255,255,255 );
end
function cLabel:Paint()
return true;
end
function cLabel:SetText ( text )
self.Text = text;
end
function cLabel:GetText()
return self.Text;
end
function cLabel:SetAlign( align )
if ( align == 0 || align == 1 ) then
self.TextAlign = align;
else
Msg( "Invalid align [" .. align .. "] passed to control!\n" );
end
end
function cLabel:GetAlign()
return self.TextAlign;
end
function cLabel:SetFont( font )
self.Font = font;
end
function cLabel:GetFont()
return self.Font;
end
function cLabel:SetColor( Color )
if ( string.lower( type( color ) ) != "color" ) then
Msg( "Invalid color passed to label!\n" );
return false;
else
self.Color = color;
end
end
function cLabel:GetColor()
self.Color = color;
end
function cLabel:Paint()
if ( self.TextAlign == 1 ) then
x = self:GetWide() / 2;
else
x = 0;
end
draw.DrawText( self.Text, self.Font, x, 0, self.Color, self.TextAlign );
return true;
end
cFrame = vgui.Create( "frame" );
cFrame:SetSize( 200,300 );
cFrame:SetPos( 100,100 );
cFrame:PostMessage( "SetTitle", "text", "cLabel Test" );
cFrame:SetVisible( true );
cLabelTest = vgui.Create( "cLabel", cFrame );
cLabelTest:SetSize( 50, 10 );
cLabelTest:SetPos( 24, 70 );
cLabelTest:SetText( "Test" );
cLabelTest:SetAlign( 1 );
vgui.Register( "cLabel", cLabel, "Panel" );
[/lua]
it may be becuse of the "||" they should be "|" instead
[QUOTE=Tobba;18742496]it may be becuse of the "||" they should be "|" instead[/QUOTE]
No they shouldn't.
[editline]10:20AM[/editline]
"|" is a bitwise operator, "||" is syntactical sugar for "or" only available in the Garrysmod lua environment.
[QUOTE=MakeR;18743199]No they shouldn't.
[editline]10:20AM[/editline]
"|" is a bitwise operator, "||" is syntactical sugar for "or" only available in the Garrysmod lua environment.[/QUOTE]
isnt that C++ or am i mixing things up?
[QUOTE=Tobba;18743462]isnt that C++ or am i mixing things up?[/QUOTE]
Garry added them to the Lua syntax for the garrysmod Lua environment, look [url=http://wiki.garrysmod.com/?title=Lua_Differences]here[/url].
Sorry, you need to Log In to post a reply to this thread.