Question About Console Warnings: Attempt to call a ______ value
38 replies, posted
I am working on a Derma window that browses directories and can open a file and I have a question about some text that shows up in the console. Here's my code:
[lua]
function FileDialog(up, open, cancel)
DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetSize( 600, 800 )
DermaPanel:SetTitle( "Open File" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( false )
DermaPanel:MakePopup()
path = "C:\\"
local DermaTextPath = vgui.Create( "DTextEntry", DermaPanel)
DermaTextPath:SetValue( path ) -- Change to default directory
DermaTextPath:SetPos( 25, 25 )
DermaTextPath:SetWide( 510 )
DermaTextPath:SetTall( 20 )
DermaTextPath:SetEnterAllowed( true )
function DermaTextPath:OnEnter()
path = DermaTextPath:GetValue()
end
local DermaListView = vgui.Create( "DListView" )
DermaListView:SetParent( DermaPanel )
DermaListView:SetPos( 25, 100 )
DermaListView:SetSize( 550, 625 )
DermaListView:SetMultiSelect( false )
DermaListView:AddColumn( "Name" )
Msg(file.Find(path)) -- Delete this after you see it printed
for k,v in pairs(file.Find(path)) do -- Make sure this works
DermaListView:AddLine(v) -- Make sure v works
end
local DermaButtonOpen = vgui.Create( "DButton")
DermaButtonOpen:SetParent( DermaPanel )
DermaButtonOpen:SetDisabled( false )
DermaButtonOpen:SetText( "Open" )
DermaButtonOpen:SetPos( 475, 750 )
DermaButtonOpen:SetSize( 100, 25 )
DermaButtonOpen.DoClick = open
local DermaButtonCancel = vgui.Create( "DButton", DermaPanel)
DermaButtonCancel:SetText( "Cancel" )
DermaButtonCancel:SetPos( 25, 750 )
DermaButtonCancel:SetSize( 100, 25 )
DermaButtonCancel.DoClick = cancel()
local DermaButtonUp = vgui.Create( "DSysButton", DermaPanel )
DermaButtonUp:SetPos( 535, 25 )
DermaButtonUp:SetSize( 20, 20 )
DermaButtonUp:SetType( "up" )
DermaButtonUp.DoClick = up
end
concommand.Add( "FileDialog", FileDialog )
function up(path)
path = path .. "../" -- Need to test if this will update in text box instantly after you replace the default text if it works
Msg( path )
end
function open(path)
print(file.Read(path))
end
function cancel()
DermaPanel:Remove()
end
[/lua]
When I click the cancel button on my window I always get a message in orange text that says: 'Attempt to call a table value'. Why would it say that? As far as I can see the cancel function has nothing to do with tables. My guess is that the orange text is some kind of warning. Oh yeah, and the cancel button doesn't work either.
I also get similar messages for my up button and my open button.
up: attempt to call a userdata value
open: attempt to call a string value (This one sort of makes sense since I am using a string in this function).
By the way, I haven't gotten the file browsing part working but if you have any suggestions feel free to throw 'em here.
snip, bad reading.
Also you need the rawio module to browse outside your gmod folder.
[QUOTE=Aide;22952079]snip, bad reading.
Also you need the rawio module to browse outside your gmod folder.[/QUOTE]
Yeah, I read somewhere that you can't leave the gmod folders but I haven't really tried working around that yet. Thanks.
Do you really expect help without posting the exact error?
Well, to start off, all of your functions are globals, so they could easily be overridden by other badly written scripts. The problem I'm seeing here is that you set the cancel's DoClick function to the return value of cancel().
[lua]DermaButtonCancel.DoClick = cancel()[/lua]
What that does, is call cancel(), gets what it returns (nil) and sets it as the DoClick function.
[QUOTE=Whitellama;22952195]Yeah, I read somewhere that you can't leave the gmod folders but I haven't really tried working around that yet. Thanks.[/QUOTE]
I don't believe that to be possible. At least haven't heard of [u]anything[/u] yet, without rawio module.
[QUOTE=|FlapJack|;22952217]Do you really expect help without posting the exact error?[/QUOTE]
I did. The ONLY thing that is printed when I press the cancel button are THESE words:
[quote]
attempt to call a table value
[/quote]
Overv is correct. You would need to remove the () from the cancel() to make it work properly.
[QUOTE=Overv;22952236]Well, to start off, all of your functions are globals, so they could easily be overridden by other badly written scripts. The problem I'm seeing here is that you set the cancel's DoClick function to the return value of cancel().
[lua]DermaButtonCancel.DoClick = cancel()[/lua]
What that does, is call cancel(), gets what it returns (nil) and sets it as the DoClick function.[/QUOTE]
Oh, I think this's because I put the parentheses after cancel. I don't have them on the other buttons but they still do that so maybe I'm wrong. Do you know what I should do instead?
I did this because that's what I was told to do here:
[url]http://mawrp.zoka.cc/forums/index.php/topic,54.msg272.html#new[/url]
At the top post (#30) you can see MawringFox gave me a small sample of how the structure of the code should work. Is what he said wrong?
You remove them, just like with the other buttons. Because then you actually [b]set[/b] the button's DoClick to your function and not just what it returns.
[QUOTE=Overv;22952421]You remove them, just like with the other buttons. Because then you actually [b]set[/b] the button's DoClick to your function and not just what it returns.[/QUOTE]
Please, take a closer look at my code up there. The cancel button was the only one with the parentheses and yet the other buttons still made an error. Is this thing even a real error? It doesn't specify any lua file or line number and it's in orange text.
Then I'm fairly sure it's because you made all your functions globals. When you make open, up and cancel locals, remember to put them above your panel creation function.
Okay well I tried making them local but it still doesn't work. Here's my newer code:
[lua]
local function up(path)
path = path .. "../" -- Need to test if this will update in text box instantly after you replace the default text if it works
Msg( path )
end
local function open(path)
print(file.Read(path))
end
local function cancel()
DermaPanel:Remove()
end
function FileDialog(up, open, cancel)
DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetSize( 600, 800 )
DermaPanel:SetTitle( "Open File" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( false )
DermaPanel:MakePopup()
path = "C:\\Program Files\\Steam\\steamapps\\whitellama11\\garrysmod\\garrysmod\\data" -- Default path
local DermaTextPath = vgui.Create( "DTextEntry", DermaPanel)
DermaTextPath:SetValue( path )
DermaTextPath:SetPos( 25, 25 )
DermaTextPath:SetWide( 510 )
DermaTextPath:SetTall( 20 )
DermaTextPath:SetEnterAllowed( true )
function DermaTextPath:OnEnter()
path = DermaTextPath:GetValue() -- My path is always what this is after enter
end
local DermaListView = vgui.Create( "DListView", DermaPanel )
DermaListView:SetPos( 25, 100 )
DermaListView:SetSize( 550, 625 )
DermaListView:SetMultiSelect( false )
DermaListView:AddColumn( "Name" )
Msg(file.Find(path)) -- Delete this after you see it printed
for k,v in pairs(file.Find(path)) do -- Make sure this works
DermaListView:AddLine(v) -- Make sure v works
end
local DermaButtonOpen = vgui.Create( "DButton", DermaPanel)
DermaButtonOpen:SetDisabled( false )
DermaButtonOpen:SetText( "Open" )
DermaButtonOpen:SetPos( 475, 750 )
DermaButtonOpen:SetSize( 100, 25 )
DermaButtonOpen.DoClick = open
local DermaButtonCancel = vgui.Create( "DButton", DermaPanel)
DermaButtonCancel:SetText( "Cancel" )
DermaButtonCancel:SetPos( 25, 750 )
DermaButtonCancel:SetSize( 100, 25 )
DermaButtonCancel.DoClick = cancel
local DermaButtonUp = vgui.Create( "DSysButton", DermaPanel )
DermaButtonUp:SetPos( 535, 25 )
DermaButtonUp:SetSize( 20, 20 )
DermaButtonUp:SetType( "up" )
DermaButtonUp.DoClick = up
end
concommand.Add( "FileDialog", FileDialog )
[/lua]
-this solution is too retarded according to whitellama's standards-
[QUOTE=Whitellama;22952342]I did. The ONLY thing that is printed when I press the cancel button are THESE words:[/QUOTE]
Then you're doing it wrong. There should be a line number.
[QUOTE=|FlapJack|;22953464]Then you're doing it wrong. There should be a line number.[/QUOTE]
Wow retard. Run the script yourself and you'll see no line number. Do you need me to take a screenshot for you?
[QUOTE=Whitellama;22953853]Wow retard. Run the script yourself and you'll see no line number. Do you need me to take a screenshot for you?[/QUOTE]
[QUOTE=Whitellama;22953853]Wow retard.[/QUOTE]
Ahahaha. Haha. Yes. Made my day.
[img_thumb]http://www.facepunch.com/fp/rating/emoticon_tongue.png[/img_thumb]
[QUOTE=|FlapJack|;22953905]Ahahaha. Haha. Yes. Made my day.
[img_thumb]http://www.facepunch.com/fp/rating/emoticon_tongue.png[/img_thumb][/QUOTE]
Do you suffer from a mental illness?
[QUOTE=Whitellama;22953946]Do you suffer from a mental illness?[/QUOTE]
This keeps getting better and better.
[QUOTE=|FlapJack|;22954029]This keeps getting better and better.[/QUOTE]
Maybe we should stop before this evolves into a flame war. I can see you quivering in fear through your avatar.
[QUOTE=Whitellama;22954088]Maybe we should stop before this evolves into a flame war. I can see you quivering in fear through your avatar.[/QUOTE]
I think you should get your eyes tested.
[QUOTE=Overv;22953325]-this solution is too retarded according to whitellama's standards-[/QUOTE]
...? Will you put it back if I snip out the word retard? ... Please?
[editline]10:34AM[/editline]
[QUOTE=|FlapJack|;22954125]I think you should get your eyes tested.[/QUOTE]
Thanks. I'll keep that in mind.
1> You dint lissen, as you dint made your vars local.
2> file,Read starts in the Gmod/data, not on the fucking C:\ drive :S
For those 2 reasons, its not working, However, next time dont try to flame the people who are trying to help you, just becouse your too dumb to read properly.
FlapJack wasn't even actually helping me. He just told me I was wrong twice when I wasn't. Still, I'll stop with the flaming.
[QUOTE=Overv;22952569]Then I'm fairly sure it's because you made all your functions globals. When you make open, up and cancel locals, remember to put them above your panel creation function.[/QUOTE]
By the way bromvlieg, he said to make the functions locals. Not the variables.
Also, if you read the whole thread you would see that in my new version of the code it DOES start in the data folder. Why are you swearing when you're trying to break up a flame war anyways? It doesn't seem like you really know the whole thread.
Actually, I have had cases where I get lua errors with no line number. It's not impossible, and it's damn annoying. Let me boot up ze ole' gmod and get your script to work.
Well actually thomas, I've got this problem fixed. Thanks for offering though.
[QUOTE=thomasfn;22955760]Actually, I have had cases where I get lua errors with no line number. It's not impossible, and it's damn annoying. Let me boot up ze ole' gmod and get your script to work.[/QUOTE]
Don't bother, the only problem here is that our local psychiatrist, whitellama, made cancel, up and open parameters of FileDialog for some reason.
Maybe we should all stop posting now. If this stays at the top of the boards for too long it'll stir up a few more insults and we've got another flame war.
[editline]11:53AM[/editline]
[QUOTE=Overv;22955921]Don't bother, the only problem here is that our local psychiatrist, whitellama, made cancel, up and open parameters of FileDialog for some reason.[/QUOTE]
Thanks Overv. Oh yeah, and the reason is because the person who wants me to write the script told me they need to be parameters. I didn't really understand it either but you can read that thread here:
[url]http://mawrp.zoka.cc/forums/index.php/topic,54.0.html[/url]
Read the top reply. That's where he put the functions in parameters so that's why I did it.
[QUOTE=Whitellama;22955893]Well actually thomas, I've got this problem fixed. Thanks for offering though.[/QUOTE]
Ehh too late. Here's the code I got:
[lua]local function FileDialog( ply, com, args )
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetSize( 400, 400 )
DermaPanel:SetTitle( "Open File" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( false )
DermaPanel:MakePopup()
local path = "C:\\Program Files\\Steam\\steamapps\\whitellama11\\garrysmod\\garrysmod\\data" -- Default path
local DermaTextPath = vgui.Create( "DTextEntry", DermaPanel)
DermaTextPath:SetValue( path )
DermaTextPath:SetPos( 25, 25 )
DermaTextPath:SetWide( 510 )
DermaTextPath:SetTall( 20 )
DermaTextPath:SetEnterAllowed( true )
function DermaTextPath:OnEnter()
path = DermaTextPath:GetValue() -- My path is always what this is after enter
end
local DermaListView = vgui.Create( "DListView", DermaPanel )
DermaListView:SetPos( 25, 100 )
DermaListView:SetSize( 550, 625 )
DermaListView:SetMultiSelect( false )
DermaListView:AddColumn( "Name" )
local function BuildListBox()
DermaListView:Clear()
for k,v in pairs(file.Find(path)) do
DermaListView:AddLine(v)
end
end
BuildListBox()
local DermaButtonOpen = vgui.Create( "DButton", DermaPanel)
DermaButtonOpen:SetDisabled( false )
DermaButtonOpen:SetText( "Open" )
DermaButtonOpen:SetPos( 475, 750 )
DermaButtonOpen:SetSize( 100, 25 )
DermaButtonOpen.DoClick = function()
print( file.Read( path ) )
end
local DermaButtonCancel = vgui.Create( "DButton", DermaPanel)
DermaButtonCancel:SetText( "Cancel" )
DermaButtonCancel:SetPos( 25, 750 )
DermaButtonCancel:SetSize( 100, 25 )
DermaButtonCancel.DoClick = function()
DermaPanel:Remove()
end
local DermaButtonUp = vgui.Create( "DSysButton", DermaPanel )
DermaButtonUp:SetPos( 535, 25 )
DermaButtonUp:SetSize( 20, 20 )
DermaButtonUp:SetType( "up" )
DermaButtonUp.DoClick = function()
path = path .. "../"
BuildListBox()
end
end
concommand.Add( "FileDialog", FileDialog )
[/lua]
Not sure that it completely works, I think you need to tweak the sizes of the controls so that they don't overlap and stuff. Hopefully you can see what changes I made and learn how stuff works better.
Okay cool.
[b]EDIT:[/b]
IT WORKS! It's not completely functioning how I want but I'll tweak it soon. When I was testing it I noticed the only way to get the files to display was to type a * after the file or folder. For example, I created a folder called llama in the data folder and the only way I could display the contents was by typing llama\* . If you're wondering why I wouldn't type the entire path, it's because you need to type the path from the data folder. Still, my question is does anybody know how I can get it to display the folder's content without using the * ?
You don't really need to show me in code if you don't want to, just explain the concept of how if you can. Here's my code which I changed to match what Thomas wrote (thanks Thomas):
[lua]
local function up(path)
path = path .. "../" -- All of these functions should be deleted or commented out
Msg( path )
end
local function open(path)
print(file.Read(tostring(path)))
end
local function cancel()
DermaPanel:Remove()
end
function FileDialog( ply, com, args ) -- CHANGE: IN PARAMETERS
local DermaPanel = vgui.Create( "DFrame" ) -- CHANGE: MADE LOCAL
DermaPanel:SetSize( 600, 800 )
DermaPanel:SetTitle( "Open File" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( false )
DermaPanel:MakePopup()
path = ""
local DermaTextPath = vgui.Create( "DTextEntry", DermaPanel)
DermaTextPath:SetValue( "Enter a directory within the garrysmod\\garrysmod\\data folder" )
DermaTextPath:SetPos( 25, 25 )
DermaTextPath:SetWide( 510 )
DermaTextPath:SetTall( 20 )
DermaTextPath:SetEnterAllowed( true )
function DermaTextPath:OnEnter() -- May need to add BuildListBox here
path = DermaTextPath:GetValue()
BuildListBox() -- You may need to remove this
end
local DermaListView = vgui.Create( "DListView", DermaPanel )
DermaListView:SetPos( 25, 100 )
DermaListView:SetSize( 550, 625 )
DermaListView:SetMultiSelect( false )
DermaListView:AddColumn( "Name" )
function BuildListBox() -- You may need to make this local again.
DermaListView:Clear()
for k,v in pairs(file.Find(path)) do -- CHANGE: REMOVED TOSTRING
DermaListView:AddLine(v) -- Make sure v works
end
end
BuildListBox() -- CHANGE: RUNS BUILD LIST BOX
local DermaButtonOpen = vgui.Create( "DButton", DermaPanel)
DermaButtonOpen:SetText( "Open" )
DermaButtonOpen:SetPos( 475, 750 )
DermaButtonOpen:SetSize( 100, 25 )
DermaButtonOpen.DoClick = function() -- CHANGE: WROTE FUNCTION HERE
print( file.Read( path ) ) -- May need to use tostring
end
local DermaButtonCancel = vgui.Create( "DButton", DermaPanel)
DermaButtonCancel:SetText( "Cancel" )
DermaButtonCancel:SetPos( 25, 750 )
DermaButtonCancel:SetSize( 100, 25 )
DermaButtonCancel.DoClick = function() -- CHANGE: WROTE FUNCTION HERE
DermaPanel:Remove()
end
local DermaButtonUp = vgui.Create( "DSysButton", DermaPanel )
DermaButtonUp:SetPos( 535, 25 )
DermaButtonUp:SetSize( 20, 20 )
DermaButtonUp:SetType( "up" )
DermaButtonUp.DoClick = function() -- CHANGE: WROTE FUNCTION HERE
path = path .. "../"
BuildListBox()
end
end
concommand.Add( "FileDialog", FileDialog )
[/lua]
Sorry, you need to Log In to post a reply to this thread.