Hi guy's making this test before i am using in my gamemode, but i can't get it to work.
it got no console error.
but, it only making one icon, put the pos of the icon, is like the second place, not the first place, if you understand..
[LUA]
function fridge()
local Model = {}
Model[1] = "models/props_junk/garbage_milkcarton002a.mdl"
Model[2] = "models/props_c17/FurnitureWashingmachine001a.mdl"
local ToolTip = {}
ToolTip[1] = "A Milk"
ToolTip[2] = "Washing Machine"
local Command = {}
Command[1] = "A Milk"
Command[2] = "A Washing Machine"
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Fridge")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
local icon = vgui.Create( "SpawnIcon", IconList )
for k,Model in pairs(Model) do
icon:SetModel( Model )
IconList:AddItem( icon )
for k,ToolTip in pairs(ToolTip) do
icon:SetToolTip(ToolTip)
end
for k,Command in pairs(Command) do
icon.DoClick = function( icon )
surface.PlaySound( "ui/buttonclickrelease.wav" )
RunConsoleCommand("gm_spawn", Model)
end
end
end
end
usermessage.Hook( "fridge", fridge )
[/LUA]
cl_init.lua:2: unexpected symbol near '['
tell us what your line 2 in cl_init.lua is
[lua]local icon[k] = vgui.Create( "SpawnIcon", IconList )[/lua]
Remove the local.
Not to flame or anything but you need to debug ur codes befor giving them out thejokker
New error:
cl_init.lua:39: ')' expected near '['
[lua]
include( 'shared.lua' )
function fridge()
local Model = {}
Model[1] = "models/props_junk/garbage_milkcarton002a.mdl"
Model[2] = "models/props_c17/FurnitureWashingmachine001a.mdl"
local ToolTip = {}
ToolTip[1] = "A Milk"
ToolTip[2] = "Washing Machine"
local Command = {}
Command[1] = "A Milk"
Command[2] = "A Washing Machine"
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Fridge")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
for k,Model in pairs(Model) do
icon[k] = vgui.Create( "SpawnIcon", IconList )
icon[k]:SetModel( Model )
IconList:AddItem( icon[k] )
for k2,ToolTip in pairs(ToolTip) do
icon[k]:SetToolTip(ToolTip)
end
for k3,Command in pairs(Command) do
icon[k].DoClick = function( icon[k] )
surface.PlaySound( "ui/buttonclickrelease.wav" )
RunConsoleCommand("gm_spawn", Model)
end
end
end
end
usermessage.Hook( "fridge", fridge )
[/lua]
In the function arguments you do not need icon[k].
Instead of:
icon[k].DoClick = function( icon[k] )
Do:
icon[k].DoClick = function()
[QUOTE=Drew P. Richard;23280676]In the function arguments you do not need icon[k].
Instead of:
icon[k].DoClick = function( icon[k] )
Do:
icon[k].DoClick = function()[/QUOTE]
that isnt much a problem what is bother me is:
[lua]
//Why call the value variable Command, the same as the table you are iterating trough?
for k3,Command in pairs(Command) do
icon[k].DoClick = function( icon[k] ) //k = nil here, use k3!
surface.PlaySound( "ui/buttonclickrelease.wav" )
RunConsoleCommand("gm_spawn", Model)
end
[/lua]
WTF.. getting this new error
cl_init.lua:32: attempt to index global 'icon' (a nil value)
[url]www.bizen.dk/error.jpg[/url]
[lua]
include( 'shared.lua' )
function fridge()
local Model = {}
Model[1] = "models/props_junk/garbage_milkcarton002a.mdl"
Model[2] = "models/props_c17/FurnitureWashingmachine001a.mdl"
local ToolTip = {}
ToolTip[1] = "A Milk"
ToolTip[2] = "Washing Machine"
local Command = {}
Command[1] = "A Milk"
Command[2] = "A Washing Machine"
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Fridge")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
for k,Model in pairs(Model) do
icon[k] = vgui.Create( "SpawnIcon", IconList )
icon[k]:SetModel( Model )
IconList:AddItem( icon[k] )
for k2,ToolTip in pairs(ToolTip) do
icon[k2]:SetToolTip(ToolTip)
end
for k3,Command in pairs(Command) do
icon[k3].DoClick = function()
surface.PlaySound( "ui/buttonclickrelease.wav" )
RunConsoleCommand("gm_spawn", Model)
end
end
end
end
usermessage.Hook( "fridge", fridge )
[/lua]
WTF.. getting this new error
cl_init.lua:32: attempt to index global 'icon' (a nil value)
[url]www.bizen.dk/error.jpg[/url]
[lua]
include( 'shared.lua' )
function fridge()
local Model = {}
Model[1] = "models/props_junk/garbage_milkcarton002a.mdl"
Model[2] = "models/props_c17/FurnitureWashingmachine001a.mdl"
local ToolTip = {}
ToolTip[1] = "A Milk"
ToolTip[2] = "Washing Machine"
local Command = {}
Command[1] = "A Milk"
Command[2] = "A Washing Machine"
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Fridge")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
for k,Model in pairs(Model) do
icon[k] = vgui.Create( "SpawnIcon", IconList )
icon[k]:SetModel( Model )
IconList:AddItem( icon[k] )
for k2,ToolTip in pairs(ToolTip) do
icon[k2]:SetToolTip(ToolTip)
end
for k3,Command in pairs(Command) do
icon[k3].DoClick = function()
surface.PlaySound( "ui/buttonclickrelease.wav" )
RunConsoleCommand("gm_spawn", Model)
end
end
end
end
usermessage.Hook( "fridge", fridge )
[/lua]
Why dont you just add them manually, instead of this complex stuff?
beacuse i wanna know how to do this..
this is just a test, so i easy can add new stuff for the gamemode i started to make, but i also thinked about just add them manually..
Stop sending things with damn wrong syntax
Just use a table with everthing inside:
[lua] stuff = {}
stuff[1] = { model = "model/path.mdl", price = 500, command = "command_1" }
stuff[2] = { model = "model/path.mdl", price = 800, command = "command_2" }
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Fridge")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
for k, v in pairs(stuff) do
icon = vgui.Create( "SpawnIcon", IconList )
icon:SetModel( v.model )
IconList:AddItem( icon )
icon:SetToolTip(v.desc) -- add desc = "" in the table.
icon.DoClick = function()
surface.PlaySound( "ui/buttonclickrelease.wav" )
LocalPlayer():ConCommand("gm_spawn", v.command)
/*Concommand so that if he uses commands
with arguments like command 1 it will be read*/
end
end
[/lua]
Rate me info, friendly, agree or late.
[QUOTE=lonewolf2;23298507]Stop sending things with damn wrong syntax
Just use a table with everthing inside:
[lua] stuff = {}
stuff[1] = { model = "model/path.mdl", price = 500, command = "command_1" }
stuff[2] = { model = "model/path.mdl", price = 800, command = "command_2" }
local frame = vgui.Create("DFrame")
local IconList = vgui.Create( "DPanelList", frame )
frame:Center()
frame:SetSize(220,200)
frame:SetTitle("Fridge")
frame:MakePopup()
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( true )
IconList:SetPadding( 4 )
IconList:SetPos(10,30)
IconList:SetSize(200, 160)
for k, v in pairs(stuff) do
icon = vgui.Create( "SpawnIcon", IconList )
icon:SetModel( v.model )
IconList:AddItem( icon )
icon:SetToolTip(v.desc) -- add desc = "" in the table.
icon.DoClick = function()
surface.PlaySound( "ui/buttonclickrelease.wav" )
LocalPlayer():ConCommand("gm_spawn", v.command)
/*Concommand so that if he uses commands
with arguments like command 1 it will be read*/
end
end
[/lua]
Rate me info, friendly, agree or late. Or dumb if I forgot something.[/QUOTE]
that's good work thank you wolf :D
Sorry, you need to Log In to post a reply to this thread.