Function stopping on hook.Add. Help!

The following is code I am using to render a beam through a function called when

function drawbeam(startpos, endpos, angle)
  local mat = Material("cable/blue_elec")
  function startDoodling()
  print("Got to function")
  render.DrawBeam(startpos, endpos, 5, 1, 1, Color( 0, 255, 255, 255 ))
  print("Got to hook.Add")
  hook.Add("PostDrawOpaqueRenderables", "LightningDoodles", startDoodling)

function SWEP:PrimaryAttack()
local muzzlepos = --don't worry, i defined this
drawbeam(muzzlepos, endpos --[===[also defined]===], angle--[===[also defined and necesarry]===])

There are two issues with this that are tied together. First, any time I load the game, this error happens:

[ERROR] gamemodes/terrortown/entities/weapons/aa.lua:36: function arguments expected near ':'
  1. unknown - gamemodes/terrortown/entities/weapons/custweapon.lua:0

This is because the SWEP:PrimaryFire() function doesn’t go all the way through to end, because it gets stopped when it goes to the drawbeam() function.

The other issue is in the drawbeam() function itself, and is the cause of the error message. The drawbeam() function ONLY goes through to the

hook.Add("PostDrawOpaqueRenderables", "LightningDoodles", startDoodling)

section, and the last print in the console log is “Got to hook.Add”.

Can anyone tell me why the drawbeam() function is only going up until the hook.Add portion, and also why the beam is not appearing. I would LOVE it if someone could help me. Thanks!

What’s line 36?

function SWEP:PrimaryAttack()

[editline]27th April 2015[/editline]

Like i said, the reason that that error is there is because the drawbeam() function doesn’t go all the way through. I just need ot know how to make the function work.

I also meant to write

hook.Add("PostDrawOpaqueRenderables", "LightningDoodles", drawbeam)

Can you post full, unedited code please?

I quite literally did nothing and the issue was resolved. I am very confused, as I restarted the game several times, and even re-wrote the script once. Does anyone want to know anything about my script?