• Timers create Lua errors
    3 replies, posted
[CODE]function CLASS:OnSpawn( ply ) local enttab = ents.GetAllAliveTiles() if( #enttab > 0 ) then local ent = table.Random( enttab ) ply:SetPos( ent.Pos + Vector( 0, 0, 32 ) ) timer.Simple( 3, function() ent:EmitSound( table.Random( ent.ActivateSounds ), 66, math.random( 70, 130 ) ) ent:SetColor( 255, 0, 0, 255 ) ent.Dropped = true end ) timer.Simple( 3, function() ent:EmitSound( table.Random( ent.FallSounds ), 33, math.random( 70, 130 ) ) ent:Drop() end ) end ply:SetGravity( 1 ) end[/CODE] This works but create lua error. [CODE][ERROR] lua/includes/extensions/table.lua:161: bad argument #1 to 'pairs' (table expected, got nil) 1. pairs - [C]:-1 2. Count - lua/includes/extensions/table.lua:161 3. Random - lua/includes/extensions/table.lua:173 4. unknown - gamemodes/******/gamemode/player_class/class_default.lua:36 Timer Failed! [Simple][@gamemodes/*****/gamemode/player_class/class_default.lua (line 34)] [ERROR] lua/includes/extensions/table.lua:161: bad argument #1 to 'pairs' (table expected, got nil) 1. pairs - [C]:-1 2. Count - lua/includes/extensions/table.lua:161 3. Random - lua/includes/extensions/table.lua:173 4. unknown - gamemodes/******/gamemode/player_class/class_default.lua:44 Timer Failed! [Simple][@gamemodes/*******/gamemode/player_class/class_default.lua (line 42)][/CODE]
ent.ActivateSounds and/or ent.FallSounds are nil.
Try test if value is table, if type(enttab) == table then Try check in timer entity valid, timer( if IsValid(ent) then code end) local ent = table.Random(enttab) ent = enttab[ent] Try talso that.
[QUOTE=Ott;45659922]ent.ActivateSounds and/or ent.FallSounds are nil.[/QUOTE] [CODE]function CLASS:OnSpawn( ply ) local enttab = ents.GetAllAliveTiles() local ent = table.Random( enttab ) if( #enttab > 0 ) then ply:SetPos( ent.Pos + Vector( 0, 0, 82 ) ) timer.Simple( 3, function() ent:SetColor( 255, 0, 0, 255 ) ent:EmitSound( "physics/metal/sawblade_stick1.wav", 66, math.random( 70, 130 ) ) ent.Dropped = true end ) timer.Simple( 4, function() ent:EmitSound( "doors/vent_open3.wav", 33, math.random( 70, 130 ) ) ent:Drop() end) end ply:SetGravity( 1 ) end[/CODE] but now other error [CODE][ERROR] gamemodes/*****/gamemode/player_class/class_default.lua:36: Tried to use a NULL entity! 1. SetColor - [C]:-1 2. unknown - gamemodes/*****/gamemode/player_class/class_default.lua:36 Timer Failed! [Simple][@gamemodes/******/gamemode/player_class/class_default.lua (line 34)] [ERROR] gamemodes/*****/gamemode/player_class/class_default.lua:44: Tried to use a NULL entity! 1. EmitSound - [C]:-1 2. unknown - gamemodes/*****/gamemode/player_class/class_default.lua:44 Timer Failed! [Simple][@gamemodes/******/gamemode/player_class/class_default.lua (line 42)][/CODE] * ents.GetAllAliveTiles() [CODE]function ents.GetAllAliveTiles() local tab = { } for _, v in pairs( ents.FindByClass( "til_tile" ) ) do if( !v.Dropped ) then table.insert( tab, v ) end end return tab end[/CODE]
Sorry, you need to Log In to post a reply to this thread.