• DPropertySheet
    12 replies, posted
I used to have a work around, but how can i paint the tabs? i forget how i used to do this :/ by paint i mean change the tab etc, like you do [lua] Blah.Paint = function() surface.draw(blah blah) end [/lua] something like that, to colour the tabs Also, Wondering if anyone could help with this: [lua] function iScript.BuyItem(ply, class) local item = iScript.Items[ class ]; if( ply:Afford(item.Price) ) then ply:ModCredits(- item.Price) ply:AddInv(item) Msg("Just purchased"..item.."For $"..item.Price) else Msg("You cannot Afford this.") end end concommand.Add("i_buyitem", iScript.BuyItem)[/lua] error: [code] *******\gamemode\------.lua:74: attempt to index local 'item' (a nil value) [/code] line 74: [lua] if( ply:Afford(item.Price) ) then [/lua]
Check if iScript.Items[ class ] returns a valid table. And if it is a table, then you cant use it in your message without give a key like item.name or item["name"]
explain further please :/
iScript.Items doesn't exist. Add iScript.Items = {} somewhere.
It does exist though. The script has other functions calling basically the same method i'm doing and it works fine.
I read it wrong. The field of iScript.Items that you entered was nil. Edit: Probably because the arguments in the callback of concommand.Add are player , command , arguments.
would this work? or do i have to call it like erm iScript.BuyItem(args[1]) [lua] function iScript.buyItem(class, ply) if( iScript.Items[ class ] == nil ) then return; end local item = iScript.Items[ class ]; if( ply:Afford(item.Price) ) then ply:ModCredits(- item.Price) ply:AddInv(item) Msg("Just purchased"..item.."For $"..item.Price) else Msg("You cannot Afford this.") end end function BuyItem(ply, cmd, args) iScript.buyItem(); end concommand.Add("i_buyitem", BuyItem) [/lua] Edit: Nevermind, it doesn't...hmm
whats the function name i wrap that in? and is it auto called by the defineskin?
If you mean force the derma skin on the client it's: Put it clientside. [lua] function GM:ForceDermaSkin() return "skin name here"; end; [/lua]
Bump. Anyone? :/
The second argument of concommand.Add, as stated by the [url=http://wiki.garrysmod.com/?title=Concommand.Add]appropriate documentation[/url], is a function of three arguments. The first argument is the player object. You have this argument correct. The second argument is the name of the command. You mistakenly expected that this function argument would be the first argument provided with the console command. The third argument is a table containing the arguments provided with the console command in a numerically indexed manner. Here is an example of how to apply this information: [lua] local function MyCommandCallback(ply, cmd, args) print("First argument:", args[1]) end concommand.Add("my_command", MyCommandCallback) [/lua] Upon line 2 of your code, in theory, the type of the variable 'item' is a table. If you attempt to concatenate a table, it will give an error. As proven by the following piece of code. [code] > print("testing "..{}) stdin:1: attempt to concatenate a table value [/code] I assume that there is a Name member of that table. Try replacing the line: [lua] Msg("Just purchased"..item.."For $"..item.Price) [/lua] with [lua] Msg("Just purchased"..item.Name.."For $"..item.Price) [/lua] However, I recommend doing this: [lua] ply:ChatPrint("Just purchased "..item.Name.." for $"..item.Price..".") [/lua] as ply.ChatPrint will print the message into the chat of the player, and the spacing within the strings will prevent it from printing: [code] Just purchasedBananaFor $5 [/code] The fact that the type of the variable of 'item' is nil when your code is executed is due to the 'class' variable being equal to the name of the command (second argument!). As the iScript.Items table does not contain any such named member, the value returned will be nil. Once you have corrected your functions, instead of using 'class', you should use 'args[1]' as that will be the first argument provided with the command. However, to prevent errors if a player gives an invalid class as the first argument, I recommend doing a check as I will demonstrate in the code below. Here is your code rewritten to both work and be of a good coding standard: [lua] function iScript.BuyItem(ply, cmd, args) local class = tostring(args[1]) local item = iScript.Items[class] if item then if ply:Afford(item.Price) then ply:ModCredits(-item.Price) ply:AddInv(item) ply:ChatPrint("You just purchased "..item.Name.." for $"..item.Price.."!") -- If item.Name is wrong, please correct it to the correct member name else ply:ChatPrint("You cannot afford this.") end else ply:ChatPrint("Invalid item class "..class.."!") end end concommand.Add("i_buyitem", iScript.BuyItem) [/lua] [editline]10:13PM[/editline] To manually paint the tabs of a DPropertySheet, I recommend creating a DPanel, setting it as the tab and overriding it's Paint function. The correct way to override a paint function (from my perspective) is as so: [lua] local the_panel = vgui.Create("whatever", whatever) function the_panel:Paint() -- code -- in here, self = the_panel print(self) print(the_panel) -- will print the same thing end [/lua]
Works perfect, thank you very much. Now to just fix the AddInv function :) away i go, thanks again deco
Sorry, you need to Log In to post a reply to this thread.