NOOB QUESTION: Can't get PrintMessage to work.

Today’s my first day messing with Garry’s Mod Lua and I’m trying to get a message to print out to chat upon startup.
I’ve already read all the wikis but I’m still stumped.

Here’s the error I’m getting.



[ERROR] gamemodes/dilbert/gamemode/shared.lua:7: attempt to call global 'PrintMessage' (a nil value)
  1. unknown - gamemodes/dilbert/gamemode/shared.lua:7


And here’s the code.

init.lua



AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua" )


shared.lua



GM.Name = "Dilbert"
GM.Author = "N/A"
GM.Email = "N/A"
GM.Website = "N/A"

function GM:Initialize()
	PrintMessage(HUD_PRINTTALK, "i,m going to kill myself on friday #wow #whoa")
end 


cl_init.lua



include("shared.lua")


How do I get this to work?

It’s because that function is supposed to be used on a player, not by itself.
http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexebff.html

In the current wiki, there’s a global version of the function as well. What’s up with that?

It’s a serverside function. You’re calling it on both the server and client.

[editline]1[/editline]

also read below

I believe you are calling it too early, try calling it somewhere like PlayerSpawn or PlayerInitialSpawn.

I can’t figure this out at all. Why do I need a SPECIFIC player for PlayerInitialSpawn when this command comes from the SERVER?
Just write the code so I can learn by example. The wikis are a goddamn mess and already have me frustrated.

Because it’s called on each player’s first spawn so you can do stuff with him.

Because PlayerInitialSpawn is called first time player joins the server. So you can do stuff. You don’t have to use player, it’s just there so you can use it.

So you just need to call your PrintMessage there so there is at least someone to send the message to, because Initialize is called before you even join the game.

Well, thanks for the answers guys. Couldn’t deal with my problem anymore though because I got distracted. Hopefully, I’ll be able to figure this out eventually.