Absolutely stumped by a BroadcastLua problem

Hi everyone. I’m having an issue with BroadcastLua not finding a function it should be. Here’s what it looks like:

init.lua



include("sv_mapvote.lua")
timer.Simple(INTERMISSION_TIME * 0.2, function() BroadcastLua("OpenMenu()") end)


sv_mapvote.lua



print("sv_mapvote loaded!")

function OpenMenu()
	local rp = RecipientFilter()
	rp:AddAllPlayers()
	
	umsg.Start("voteopen", rp)
	umsg.End() --Was that so hard?
	--gmod.BroadcastLua(votepanel)
end


The error always looks like this:
:1: attempt to call global ‘OpenMenu’ (a nil value)

So if anyone can help with this oddity, that would be great.

BroadcastLua() sends lua to clients. That function you want it serverside.

Know the problem now?

Hmm… this is weird. After removing the quotes around OpenMenu(), it worked, but not without another error:
Timer Error: ZombieSurvival/gamemode/init.lua:757: bad argument #1 to ‘BroadcastLua’ (string expected, got no value)

EDIT: @iRzilla: So what should I use in place of it?

Just use: OpenMenu()

Without the BroadcastLua.

Alright, thanks. I think I’ll make a note of that in the BroadcastLua section of the wiki.

You got it all wrong. BroadcastLua is for sending a string of lua code that clients will execute, it has nothing to do with running functions. In your case the code was running the function expecting it would return a string and it errors because the function does not return a string.

Ah, I’ll go fix the wiki page I edited then.

Way ahead of you. :angel:

Lol, Ninja’d x3 now. Although, I think it is still technically correct to say that it can accept functions as well, since that is what it was doing, right?

Not really, some hooks/functions do require functions as arguments but in those cases it’s just the name, you don’t actually call it. Example :

[lua]function foo()
return 5
end

function bar()
var = 4
end
print(foo()) – This will print 5 because the code executes the function and then uses what the function returned
print(bar()) – This won’t print anything since the function doesn’t return anything[/lua]

Oh, ok.