timer.Simple

From Garry's Mod
Jump to: navigation, search
 timer.Simple( )

Contents

Description

Creates a simple timer that runs the given function after a specified delay.

For a more advanced version that you can control after creation, see timer.Create.

NOTE

Timers use CurTime for timing.

WARNING

Timers won't advance while the client is timing out from the server.

Arguments

number delay

How long until the function should be ran (in seconds). Use 0 to have the function run in the next GM:Think.

Arguments

function func

The function to run after the specified delay.

Examples

Example

Print "Hello World" after 5 seconds.

timer.Simple( 5, function() print( "Hello World" ) end )

Output:

Hello World

Examples

Example

Spawns 5 zombies and creates a timer.Simple that removes them in 11, 12, 13, 14, and 15 seconds.

for i = 1, 5 do
	local zombie = ents.Create("npc_zombie")
	zombie:SetPos( Vector( i*40, 0 , 250 ) )
	zombie:Spawn()

	timer.Simple( 10 + i, function() zombie:Remove() end  )
end

Output:

--11 seconds into game 1st zombie disappears

--12 seconds into game 2nd zombie disappears

etc.
Personal tools
Navigation