• Set variable on ents.create entity.
    6 replies, posted
I'm trying to set variable on ents.create entity. But it should be a table so it can't be NWVar I think? [CODE] local tab = {"hey","hey2"} local ent = ents.Create("some_entity") ent:SetPos(pos) ent.VarTable = tab ent:Spawn() -- In ENT:Initialize or any ENT: function of some_entity ENT:Initialize() PrintTable(self.VarTable) --nil end [/CODE]
[QUOTE=coderfather;52876858]I'm trying to set variable on ents.create entity. But it should be a table so it can't be NWVar I think? [CODE] local tab = {"hey","hey2"} local ent = ents.Create("some_entity") ent:SetPos(pos) ent.VarTable = tab ent:Spawn() -- In ENT:Initialize or any ENT: function of some_entity ENT:Initialize() PrintTable(self.VarTable) --nil end [/CODE][/QUOTE] Are you printing clientside? Your vartable is not networked in this instance.
[QUOTE=bilbasio;52876877]Are you printing clientside? Your vartable is not networked in this instance.[/QUOTE] I tried it on server. But I want make it shared too.
[QUOTE=coderfather;52876884]I tried it on server. But I want make it shared too.[/QUOTE] It's a bit hard to help you only with these 10 lines. You need to share a bit more code. Are you coding in a gamemode environment or just coding an entity?
[QUOTE=bilbasio;52876962]It's a bit hard to help you only with these 10 lines. You need to share a bit more code. Are you coding in a gamemode environment or just coding an entity?[/QUOTE] It's an addon. I think I was clear. I just want get a table from server to use it in entity clientside and serverside both. Why I am not creating table in entity, you may ask. It's up to situation and it has to be in that server file.
[QUOTE=coderfather;52877039]It's an addon. I think I was clear. I just want get a table from server to use it in entity clientside and serverside both. Why I am not creating table in entity, you may ask. It's up to situation and it has to be in that server file.[/QUOTE] You need to send it to the client. If you want to send a table .. go with the net libary. [url]https://wiki.garrysmod.com/page/Net_Library_Usage[/url] Create some code that will sync the table. Or use the Ent:SetNW<type>(name,varable) (Like [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNWString]Entity:SetNWString[/url]) This doesn't support tables tho.
[QUOTE=Nak;52877634]You need to send it to the client. If you want to send a table .. go with the net libary. [url]https://wiki.garrysmod.com/page/Net_Library_Usage[/url] Create some code that will sync the table. Or use the Ent:SetNW<type>(name,varable) (Like [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetNWString]Entity:SetNWString[/url]) This doesn't support tables tho.[/QUOTE] Well, I told it doesnt support anyway. I am already using net on ent use.
Sorry, you need to Log In to post a reply to this thread.