Anmelden

Archiv verlassen und diese Seite im Standarddesign anzeigen : erste LUA versuche



gamerpaddy
18.04.2009, 21:14
Hallo,
da ich noch ein newbie in LUA bin habe ich mal eine frage:
ich habe mir ein kleines script zusammen gescriptet wo als test für spätere dinge dienen soll

hier das script:
HTMLScript = [[
<html>
<body bgcolor=#FFFFFF>
<div style="text-align: center;">
<div style="font-size: 30px; font-family: impact; width: 100%; margin-bottom: 5px;">hahahah LOL</div><br>
<h2>News:</h2>
HTML VGUI YAY!<br>
:D test etstetsetstes.<br>
<br>
<h2>:D:</h2>
1. suckszucsucksu.<br>
<br>
<div style="width: 100%; text-align: center; margin: 10px; font-weight: bold;">by me LOL</div>
</div>
</div>
</body>
</html>
]]
if not file.Exists( "lol.txt" ) then
file.Write( "lol.txt", HTMLScript )
end
function TESTVGUI()
local PropertySheet = vgui.Create( "DPropertySheet" )
PropertySheet:SetParent( DermaPanel )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 340, 315 )

local SheetItemOne = vgui.Create ("SheetItemOne");
SheetItemOne:SetSize( 1000, 900 );
SheetItemOne:SetPos( 100, 100 );
SheetItemOne:SetVisible( true );
SheetItemOne:MakePopup( );
SheetItemOne:PostMessage( "SetTitle", "text", "test vgui lol" );

local Button = vgui.Create ("Button", SheetItemOne );
Button:SetText( "rofl :D" );
Button:SetPos( 30, 5 );
Button:SetWide( 100 );
function Button:DoClick( )
DermaImage = vgui.Create( "DImageButton", DermaPanel )
DermaImage:SetPos( 25, 50 )
DermaImage:SetImage( "console/background01" ) -- Set your .vtf image
DermaImage:SizeToContents()

end

end

local SheetItemTwo = vgui.Create ("SheetItemTwo");
SheetItemTwo:SetSize( 1000, 900 );
SheetItemTwo:SetPos( 100, 100 );
SheetItemTwo:SetVisible( true );
SheetItemTwo:MakePopup( );
SheetItemTwo:PostMessage( "SetTitle", "text", "test vgui2 lol" );

local Button = vgui.Create ("Button", SheetItemTwo );
Button:SetText( "kill :D" );
Button:SetPos( 30, 5 );
Button:SetWide( 100 );
function Button:DoClick( )
RunConsoleCommand( "kill" );

end

local Button2 = vgui.Create ("Button2", SheetItemTwo );
Button2:SetText( "g00gle.de" );
Button2:SetPos( 130, 5 );
Button2:SetWide( 100 );
function Button2:DoClick( )
local HTMLFrame = vgui.Create( "HTML", SheetItemTwo )
HTMLFrame:SetPos( 25, 50 )
HTMLFrame:SetSize( SheetItemTwo:GetWide() - 50, SheetItemTwo:GetTall() - 150 )
HTMLFrame:SetHTML( file.Read( "lol.txt" ) )

end

end

PropertySheet:AddSheet( "fail menu", SheetItemOne, "gui/silkicons/user", false, false, "lololololol" )
PropertySheet:AddSheet( "KILL MENU", SheetItemTwo, "gui/silkicons/group", false, false, "Hazcheez ;D" )

concommand.Add( "vguilol", TESTVGUI );

nur wen ich ingame lua_openscript vguilol.lua eingebe kommt


autorun/vguitest.lua:77: '<eof>' expected near 'end'

Pac_187
18.04.2009, 21:16
Jo 1 end zu viel halt...

Einfach das letzte löschen, auch wenn er sagt das es 1 zu wenig ist.

gamerpaddy
18.04.2009, 21:18
dan kommt ingame bei lua_openscript


autorun/vguitest.lua:49: attempt to index global 'vgui' (a nil value)

und der command geht auch nicht :-? :|

Pac_187
18.04.2009, 21:26
Warum steht in Zeile 28,35 und 49 "SheetItemOne" bzw. "SheetItemTwo" ?

Meines Wissens nach sind das keine Bestandteile der Vgui Library!

gamerpaddy
18.04.2009, 21:28
achso kann man derma und vgui nicht mischen? o-O

Pac_187
18.04.2009, 21:31
Was ich damit sagen will ist,
es gibt kein Objekt namens SheetItemOne bzw. SheetItemTwo
in der der List an verfügbaren VGUI Elementen: http://wiki.garrysmod.com/wiki/?title=Base_VGUI_Elements_List

Will heißen, wo erstellst du die?



Desweiteren sieht mir dein Code eher nach Copy Pasta' aus.

BennyG
18.04.2009, 21:31
SheetItemOne bzw Two ist weder Bestandteil des Vgui oder Derma Library.
(Mal abgesehn davon, dass Derma ja eigentlich vgui ist...)

Derma's (http://wiki.garrysmod.com/wiki/?title=Derma_Controls)

EDIT: Pac war schneller :'(

gamerpaddy
18.04.2009, 21:38
das mit dem sheet ist von hier:
http://www.facepunch.com/showthread.php?t=543184

2ter beitrag -> DPropertySheet
ich wollte ein paar tabs machen

Pac_187
18.04.2009, 21:40
Ja die existieren ja auch, aber nicht SheetItemOne und SheetItemTwo.

Fang erstmal mit der Anleitung zu Lua an ;)
http://www.lua.org/manual/5.1/index.html#contents

Um zu verstehen was Tables und so Zeugs sind.

BennyG
18.04.2009, 21:42
Da ist es aber auch richtig gemacht.
Lediglich du hast es falsch abgeschaut, denn SheetItemOne und Two werden da aber auch nicht erstellt.

(Und falls du nicht weißt was wir meinen,wir meinen dass, was du mit vgui.Create() erstellst, nicht den VariablenNamen)

gamerpaddy
19.04.2009, 00:05
so ich habe jetzt ma den script von http://wiki.garrysmod.com/wiki/?title=Lua:VGUI_Basics
kopiert

function TestVGUI( )

local Frame = vgui.Create( "Frame" ); //Create a frame
Frame:SetSize( 200, 200 ); //Set the size to 200x200
Frame:SetPos( 100, 100 ); //Move the frame to 100,100
Frame:SetVisible( true ); //Visible
Frame:MakePopup( ); //Make the frame
Frame:PostMessage( "SetTitle", "text", "This is the title" ); //Set the title to "This is the title"

local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
Button:SetText( "Click me!" ); //Set the button's text to "Click me!"
Button:SetPos( 30, 5 ); //Set the button's position relative to it's parent(Frame)
Button:SetWide( 100 ); //Sets the width of the button you're making
function Button:DoClick( ) //This is called when the button is clicked
self:SetText( "Clicked" ); //Set the text to "Clicked"
end

end

concommand.Add( "testvgui", TestVGUI );

aber ingame passiert genau das gleiche wie bei meinem wen ich den command testvgui eingebe ->


vguitest.lua:3: attempt to index global 'vgui' (a nil value)

Pac_187
19.04.2009, 10:02
Es ist DFrame und nicht Frame und DButton und nicht Button!

Alex22
19.04.2009, 11:47
Es ist DFrame und nicht Frame und DButton und nicht Button!

Sieht eher so aus, als hätte er das Script nicht in den Client Ordner gepackt.

Du musst deine Lua Files in den Ordner:
XX\lua\autorun\client
schieben.

Und ich glaube eine init.lua und eine cl_init.lua reinpacken. In init.lua muss:
AddCSLuaFile( "DATEINAME.lua" )
und in der cl_init.lua:
include( 'DATEINAME.lua' )
stehen.

Nicht meckern wenn das nicht stimmt, nur ich hatte das selbe Problem und es wurde damit gelöst.

BennyG
19.04.2009, 13:00
CJ[CSR];354238']so ich habe jetzt ma den script von http://wiki.garrysmod.com/wiki/?title=Lua:VGUI_Basics
kopiert

function TestVGUI( )

local Frame = vgui.Create( "Frame" ); //Create a frame
Frame:SetSize( 200, 200 ); //Set the size to 200x200
Frame:SetPos( 100, 100 ); //Move the frame to 100,100
Frame:SetVisible( true ); //Visible
Frame:MakePopup( ); //Make the frame
Frame:PostMessage( "SetTitle", "text", "This is the title" ); //Set the title to "This is the title"

local Button = vgui.Create( "Button", Frame ); //Create a button that is attached to Frame
Button:SetText( "Click me!" ); //Set the button's text to "Click me!"
Button:SetPos( 30, 5 ); //Set the button's position relative to it's parent(Frame)
Button:SetWide( 100 ); //Sets the width of the button you're making
function Button:DoClick( ) //This is called when the button is clicked
self:SetText( "Clicked" ); //Set the text to "Clicked"
end

end

concommand.Add( "testvgui", TestVGUI );

aber ingame passiert genau das gleiche wie bei meinem wen ich den command testvgui eingebe ->


vguitest.lua:3: attempt to index global 'vgui' (a nil value)


Ich hab jetzt auch noch mal ne ganz dumme Vorahnung, dass du das alles aufen Server ausführst, da gibs das vgui Library ja auch nicht.

gamerpaddy
19.04.2009, 17:02
ich führ die scripts im singleplayer aus
wo den sonst?
der script liegt in lua/autorun/client (wie im video tutorial)

EDIT: so ich habe den bug behoben warum es nicht ging ..
danke benny das du gesagt was fehlt (vgui "library")

ich hab jetzt das genommen
http://garrysmod.org/downloads/?a=view&id=21577
geht auch