variables in entities not working

Hey guys I’m trying to make a crafting table and I have made vars to show if an item is inside the entity.

I’m calling them like this:



function ENT:Initialize()
	self:SetModel("models/props_c17/FurnitureTable002a.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	self:SetUseType(SIMPLE_USE)
	local phys = self:GetPhysicsObject()
	if IsValid(phys) then phys:Wake() end
	
	self.allowInput = true
	self.hasMat1 = false
	self.hasMat2 = false
	self.hasMat3 = false
	self.hasMat4 = false
	self.hasMat5 = false
	self.hasMat6 = false
	self.hasMat7 = false
	self.hasMat8 = false
	self.hasMat9 = false
end


And changing and getting them here.



function ENT:Think()
	/* Recipes */
	if self.hasMat2 == true and self.hasMat4 == true and self.hasMat7 == true then
		self.allowInput = false
	end	
	
	if self.hasMat8 == true and self.hasMat4 == true and self.hasMat5 == true then
		self.allowInput = true
	end
		
	if self.hasMat3 == true and self.hasMat2 == true and self.hasMat6 == true then
		self.allowInput = true
	end
	
	if self.hasMat3 == true and self.hasMat4 == true and self.hasMat5 == true then
		self.allowInput = false
	end	
end


The problem: When a bool is on true every single ent spawned by players changes to true.
How do I make it only for the entity that is spawned, not every single?

How are you changing them?

In the think I changed allowInput to true by doing this:


self.allowInput = false

bump

I’m not sure this will fix your problem, but you could try

http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf1c0.html

as your hook, and obviously name the specific entity.

Also, some basic code formatting tips (makes it look nicer, more professional, and it’s shorter ) take em or leave em.

-snip- apparently I’m dumb.

And in your ENT:Think(), keep in mind that



	if self.hasMat2 == true and self.hasMat4 == true and self.hasMat7 == true then
		self.allowInput = false
	end


is the same as:



	if self.hasMat2 and self.hasMat4 and self.hasMat7 then
		self.allowInput = false
	end


again, doesn’t change the efficiency of the code whatsoever, but it does make it look nicer and a little more professional. Take it or leave it. :slight_smile:

That won’t even work.

Interesting. Why not?

That would be the first language, in which you can use Operators to access a variable.
You can’t form the variable name out of Strings

Figured it out myself.

I used this: http://wiki.garrysmod.com/page/Networking_Entities

[editline]7th December 2013[/editline]

Really, more professional my ass.

I love equal signs.

It should be:



self[ "hasMat" .. i ] = false


Ah. I knew it was possible, I just formatted incorrectly. Thanks!