Another unreasonable lua error.

I am trying to create a new SNPC, in this particular error, i am trying to add an automatic musical theme which starts upon the spawn of the SNPC…

This is the error i am constantly recieving no matter what i do, on line 35 of the SNPC code, there is supposed to be a “(” near “self” and no matter where i place it, it refuses to work properly.


 function ENT:OnSpawn
  self:(CreateSound = "npc/godzilla/Theme.mp3")
 end

there is the code, that is’nt the original, and seriously, i’ve attempted to place brackets everywhere, nothing seems to work… so if you understand how to resolve this, i’d like to know!

Honestly, how do you expect that code to work?

[editline]…[/editline] I’ve no clue how to play the sound, but I can tell you this:
“Near ‘self’” means it must be either before or after self, not one character away.

I guess pepper has his shitposting day today, anyway, go read the Lua-PIL again.

Create an usermessage hook in cl_init.lua:



usermessage.Hook("PlayGodzillaTheme", function()
	surface.PlaySound("npc/godzilla/Theme.mp3")
end)


Place this in your entity’s init.lua:



function ENT:Initialize()
	umsg.Start("PlayGodzillaTheme")
	umsg.End()
end


Edit: In fact, try placing this in the entity’s cl_init.lua instead:



function ENT:Initialize()
	surface.PlaySound("npc/godzilla/Theme.mp3")
end


There is a difference between CreateSound and surface.PlaySound.

Alright alright:



soundFile = Sound("npc/godzilla/Theme.mp3")
function ENT:Initialize()
	local sound = CreateSound(self, soundFile)
	sound:Play()
end


Won’t work either, the sound will get purged because it’s not referenced anymore, you need to save it in the entity.

What about
[lua]
function ENT:Initialize()
local self.sound = CreateSound(self, Sound(“npc/godzilla/Theme.mp3”))
self.sound:Play()
end
[/lua]

That would work right ?

That would give you a syntax error lol.

Not having to deal with the fact that your sounds aren’t working… I haven’t seen anybody point out that his ENT:OnSpawn has no () after it…