• Acces variable from anouther entity
    3 replies, posted
Okay so say there is entity b, and entity a, When they collide I want entity b to set a variable on entity b. How would I do this? Do I have to use the netLibray? Thanks
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/StartTouch]ENTITY/StartTouch[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/EndTouch]ENTITY/EndTouch[/url] You can assign a variable to an entity like this: [Lua] ent.Variable = "Hello" [/lua]
[QUOTE=meharryp;46876680][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/StartTouch]ENTITY/StartTouch[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/EndTouch]ENTITY/EndTouch[/url] You can assign a variable to an entity like this: [Lua] ent.Variable = "Hello" [/lua][/QUOTE] But say I have a variabkle called test in the shared.lua file of one entity, Can I acces it the same way so ent.test = true
Let's say you have 2 entites. In the shared.lua of each you have a variable called ENT.Hello. Variables assigned to an entity like this become attached to the entity. Let's say you have a function later on that takes an entity as an argument. If you, for example, called the argument entToDo, you can do print( entToDo.Hello ), which will access the value of the variable Hello from the entity.
Sorry, you need to Log In to post a reply to this thread.