Confusion with local functions (Failure to be called)

I make multiple mods and the scripts are similar yet different. The problem is that if two functions have the same ID/Name they overwrite each other.

So I think “Oh maybe… I can use local functions! those are only in the scope of the entire script and not global, right?”

So I use local, the hooks havent changed but each function has local in front of it.

Then no function can be called, they work with hooks yes, but I cant call them from other local functions.

Code:




local function PlyVehicle(ply, veh)

		if SERVER then 
		
				MES("LAL")
			
		end
end

 local function MES(str)
if SERVER then 
PrintMessage(3,str)
end
end


Error


attempt to call global 'MES' (a nil value)


Thank you for taking time to read this


local function MES(str)
    if SERVER then 
        PrintMessage(HUD_PRINTTALK, str)
    end
end

local function PlyVehicle(ply, veh)
    if SERVER then 
        MES("LAL")
    end
end

In your case you have to define your function “MES” before your function “PlyVehicle”.

Local stuff needs to be indexed before referencing it, so move MES above the other function. If you have to use both functions calling each other, you can do this:
[lua]local func1
local func2

func1 = function()
func2()
end

func2() = function()
func1()
end[/lua]

Markusmarkusz’s explanation worked, thank you.

I do have another issue that i’m trying to solve, which is that SetPlaybackRate on multplayer makes my animation play slower than on multiplayer.