Automatic Message script

Hello , I do a little code, but it does not seem to work can you help me. thank you

My code :


function MsgAuto()
MsgAuto = true

if MsgAuto then
	ply:ChatPrint( ply:GetName().. " à TEST" )
	timer.Create( "automsg", 10, 0, MsgAuto)
	end
end


MsgAutoActivated = true

if MsgAutoActivated then
	timer.Create( "automsg", 10, 0, MsgAuto)
end

function MsgAuto(ply)
 for k,ply in pairs(player.GetAll()) do
  ply:ChatPrint( ply:GetName().. " à TEST" )
 end
end

end


Try that maybe

it’s doesn"t work

[ERROR] A runtime error has occurred in “addons/darkrpmodification/lua/darkrp_modules/ano_cmd/sv_ano.lua” on line 37.
The best help I can give you is this:

bad argument #4 to ‘Create’ (function expected, got boolean)

Hints:
- No hints, sorry.

The responsibility for this error lies with (the authors of) one (or more) of these files:
1. addons/darkrpmodification/lua/darkrp_modules/ano_cmd/sv_ano.lua on line 37
2. gamemodes/sschoolrp/gamemode/libraries/fn.lua on line 80
3. gamemodes/sschoolrp/gamemode/libraries/modificationloader.lua on line 90
4. gamemodes/sschoolrp/gamemode/libraries/modificationloader.lua on line 141
5. gamemodes/sschoolrp/gamemode/init.lua on line 81
------- End of Simplerr error -------

[editline]28th July 2015[/editline]

Pleas, help me

try making the function from Xaotic’s post without arguments?


 function MsgAuto() -- no arguments
 for k,ply in pairs(player.GetAll()) do
  ply:ChatPrint( ply:GetName().. " à TEST" )
 end
end


?

Its doesnt work help me pleas

You’d need to call your function in order for something to happen.




AutoMSG = true

function MsgAuto()
    if AutoMSG then
        for k, v in pairs(player.GetAll()) do
	     v:ChatPrint( v:Nick().. " à TEST" )
        end
    end
end

timer.Create( "automsg", 10, 0, MsgAuto)



Why make those global?

It’s easier to work with for those people who don’t know much about coding. Imagine going through thousands of lines of coding and trying to find your local variable. But in this case you could use a console variable.

Ok so. You’re going to make a global variable caled MsgAuto, then overwrite it with a function called MsgAuto which checks if MsgAuto is nil.

Don’t encourage bad practice.
Globals should only be used when their needed.

Yea thanks. LegoGuy pointed that out to me.

Actually that code is valid. Autistic but valid. Since the timer just contains a reference the global variable could be unset but it’d continue to call its ref to the function.

Since functions are truthy it will still evaluate the if as true although for the wrong reasons.

This being said that code is dumb and wrong.

-edit-
burn it with fire

Thats what Ctrl + F is for.