Hello
I got this error when i tried to script this simple code.
[code]
[ERROR] lua/heyo.lua:1: attempt to index global 'ENT' (a nil value)
1. unknown - lua/heyo.lua:1
[/code]
[code]
function ENT:Initialize()
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
self:SetModel("models/props_c17/consolebox01a.mdl")
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
function ENT:Use(a , c)
if ent:IsPlayer() then
local ply = LocalPlayer()
local entname = "Benny"
local plyhealth = ply:Health()
a:ChatPrint(entname)
if 20 <= plyhealth then
c:SetHealth(c:Health() + 20)
end
end
end
[/code]
Thanks
have you tried putting your script into "/lua/entities" instead of just "/lua"?
I just tried it, but still giving the same error
[QUOTE=Denvist;50450550]I just tried it, but still giving the same error[/QUOTE]
Make sure you place the files in ONE folder in the entities folder.
lua/entities/yourentity
Still wont work and giving the same error.
But could the reason for this be that im trying to do this for single player and not for server?
This may help [url]https://www.youtube.com/watch?v=uE5A4AwwIK8[/url]
[QUOTE=Denvist;50453317]But could the reason for this be that im trying to do this for single player and not for server?[/QUOTE]
Possibly. Try doing a simple client check like
[CODE]
if !( CLIENT ) then return end
[/CODE]
At the top of your script
But remember, you can't spawn entities unless the code is run serverside, so make sure the check is below your entity's spawnfunction
It still get the same error...
[QUOTE=Denvist;50453366]It still get the same error...[/QUOTE]
Did you look at the video i posted?
Yep, i did. I did what he did. But still getting the same error.
And yes i tried to spawn it in the menu, but i cant do anything with it like moving it, Press E on it nothing. Its just a model
As you can see here..
[IMG]https://i.gyazo.com/f5605065498e264345c95d21ef4a5dd7.png[/IMG]
[IMG]https://i.gyazo.com/96761944a3327fcecda69c7bf0ed9f3d.png[/IMG]
[QUOTE=Denvist;50453387]Yep, i did. I did what he did. But still getting the same error.
And yes i tried to spawn it in the menu, but i cant do anything with it like moving it, Press E on it nothing. Its just a model
As you can see here..
[IMG]https://i.gyazo.com/f5605065498e264345c95d21ef4a5dd7.png[/IMG]
[IMG]https://i.gyazo.com/96761944a3327fcecda69c7bf0ed9f3d.png[/IMG][/QUOTE]
Can you post all of your 3 ent files on pastebin, thanks
Here is codes:
cl_init.lua: [url]http://pastebin.com/dD8wSuLD[/url]
init.lua: [url]http://pastebin.com/FViwxb5h/?e=1[/url]
shared.lua: [url]http://pastebin.com/HCpxEAhu[/url]
I hope this helps
Try doing AddCSLuaFile() at the top of your shared file
[editline]4th June 2016[/editline]
If that doesn't work, I guess the next step would be to try merging your serverside, clientside and shared files into a single file, using if ( CLIENT ) then and if ( SERVER ) then to run different parts of the code. I think your files may be getting mixed up with Lua, and it may be thinking all your separate files are separate entities or something. I'm just guessing that because most entities usually are only in one file
[QUOTE=MPan1;50453446]Try doing AddCSLuaFile() at the top of your shared file
[editline]4th June 2016[/editline]
If that doesn't work, I guess the next step would be to try merging your serverside, clientside and shared files into a single file, using if ( CLIENT ) then and if ( SERVER ) then to run different parts of the code. I think your files may be getting mixed up with Lua, and it may be thinking all your separate files are separate entities or something. I'm just guessing that because most entities usually are only in one file[/QUOTE]
Nope still arent working :(
Actually, I just noticed your code doesn't have a single [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/SpawnFunction]ENT:SpawnFunction[/url]. Try adding one, according to the wiki you need one for the entity to be spawnable
Can someone else try it on there gmod, i would but im not at my pc im on my tablet on holiday. Im just thinking the code looks fine and it may just be Denvist's gmod.
Yeah, I'm going to test it, hold on
[editline]4th June 2016[/editline]
I changed your code around a little bit, and this seems to work for me:
[CODE]
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Test Entity"
ENT.Spawnable = true
if ( SERVER ) then
function ENT:Initialize()
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetUseType( SIMPLE_USE )
self:SetModel( "models/props_c17/consolebox01a.mdl" )
local phys = self:GetPhysicsObject()
if ( IsValid( phys ) ) then phys:Wake() end
end
function ENT:Use( activator, caller, usetype, val )
if caller:IsPlayer() then
caller:ChatPrint( "Benny" )
if caller:Health() > 20 then
caller:SetHealth( caller:Health() + 20 )
end
end
end
end
if ( CLIENT ) then
function ENT:Draw()
self:DrawModel()
end
end
[/CODE]
I just put that in lua/entities and named it a random name, it's just one file and it seems to work for me
[editline]4th June 2016[/editline]
By the way, your ENT:Use function was a bit broken because you never defined ent and you expected LocalPlayer() to work serverside (ENT:Use is a serverside function and LocalPlayer() is a clientside one), so I changed it a bit to do what I think you wanted it to do
Still arent working for me. It might be my gmod.
I'll go and reinstall it.
But thanks for your help :)
Just verify your game cache
I just uninstalled, but thanks. Im downloading 9 mb so, its np for me :)
[editline]4th June 2016[/editline]
Still arent working after the re-install :(
It says the same error
well i am no expert but i do my developing stuff on a local dedicated server maybe it can help here is the link for wiki :[url]https://wiki.garrysmod.com/page/Hosting_A_Dedicated_Server[/url]
hope this can help !
Sorry, you need to Log In to post a reply to this thread.