Ok so this has been giving me a splitting headache for the last two hours and I can't make any sense of exactly why it is erroring on me.
When attempting to spawn an energy upgrade I receive this error:
Entity [84][prop_physics]
[addons\space combat\lua\weapons\gmod_tool\stools\sc_energy_upgrade.lua:53] attempt to call global 'Make_sc_energy_upgrade' (a nil value)
Type: Medium Cap Battery
STOOL Trace hit: Entity [84][prop_physics]
So I immediately opened up notepad++ and went to line 53 and the code seems perfectly fine...
[url]http://pastebin.com/R4qrX6jX[/url]
Also here is the init.lua
[url]http://pastebin.com/XzYTmVZN[/url]
I can't figure out for the life of me why it keeps erroring because there seems to be nothing wrong with the code. Anyone have an idea?
Is it a serverside error or a clientside error? If it's running on the client, it would error because Make_sc_energy_upgrade was only defined on the server.
Errors on both. I can't use it on my server or locally. And hai Entoros :D
Hey Xero :D
[del]If the function is nil, my guess is either a) there's an error initializing it, b) it's never initialized, or c) something is overriding it before the time you get to use your function.[/del]
OHH, ok, I see the problem. Issue is you're initializing the global function in your entity code, which isn't always necessarily run before your entity is initialized. It'd be safer to declare your function in a lua/autorun file so it'll for sure be in existence by the time you get around to using your tool.
No idea how I'd do that but it's a start. I'll figure it out somehow. Thanks Ent.
Is this an addon or a gamemode? If it's a gamemode, put the function in your init.lua. If it's an addon, create a sub-folder in your lua folder called "autorun", and then create a lua file in there and paste the function into it. The autorun folder is automatically run as the name suggests, and is loaded when the lua state is initialized.
It's an addon. Thank's again.
[editline]5th November 2010[/editline]
Ok, so made a little progress...I think. Now I get this
Entity [85][ship_core_minmatar]
Attempted to create unknown entity type sc_energy_upgrade!
[@addons\space combat\lua\autorun\sc_energy_upgrades.lua:6] Tried to use a NULL entity!
This is the newly created autorun file. Called simply sc_energy_upgrades.lua.
[url]http://pastebin.com/XAJ2jZWk[/url]
That means either a) there's an error in your entity code (which you should be able to find in your console) which makes it so it won't load, b) your entity code is in the wrong place, or c) your entity code doesn't have all the necessary variables to load.
I believe I've found the problem to be that the autorun calls "Make_sc_energy_upgrade(pl, Pos, Ang, type, trace)"
But the init.lua only defines "Make_sc_energy_upgrade(pl, Pos, Ang, type)"
Going to try removing trace.
Ok, so I removed trace and I still get the same exact error. Still cannot figure out what's wrong with it.
Sorry, you need to Log In to post a reply to this thread.