ENT:StartTouch

So I am here again the “Noob”. I am working on my addon and I want it so when my “cooking_pot” touches my cooker it will go onto of the cooker it will remove its self.

Part from my
Init.lua


function ENT.StartTouch(ent)
	if ent:GetClass() == "cooking_pot" then
		ent:Remove()
		self.isPotted = true
		self:SetColor(Color(0,0,255))
	end
end

function ENT:StartTouch(ent)
	if ent:GetClass() == "dough" and self.isBaking == false and self.isPotted then
		ent:Remove()
		self.isBaking = true
		self.finishBakeTime = CurTime() + 5
	end
end

I dont know how to get around this as I know that they are conflicting with each other as If I take one away the other works.
**
Any help would be amazing**

You can put both if statements in one StartTouch function.

Try to learn arithmetics and some general logical puzzles before/during learning how to lua <3

Also, how about:



function ENT.StartTouch(ent)
	if ent:GetClass() == "cooking_pot" then
		ent:Remove()
		self.isPotted = true
		self:SetColor(Color(0,0,255))
	end
	if ent:GetClass() == "dough" and self.isBaking == false and self.isPotted then
		ent:Remove()
		self.isBaking = true
		self.finishBakeTime = CurTime() + 5
	end
end


literally removed just three lines.

Alternatively you can use elseif.

or rewatch Code Blue’s video.

you only know that because you help me before and I mentioned it

[editline]28th September 2016[/editline]

Thanks was being dumb before asking question and didn’t fully understand StartTouch

Shouldnt it be ENT:StartTouch instead of ENT.StartTouch ?

I see

Not the same thing. Notice the “:” and the “.”

yup thanks

: is for dynamic functions
. is for more static functions

Alternatively, you can’t use the self variable in static functions.

Eh not really, the only thing “:” does is implicitly declare “self” argument. It’s just a syntactic sugar.

These are identical:



function x.y(self)
end

function x:y()
end


To be exact, these* are identical



x = {}
x["face"] = "punch"

function x.y()
print(x["face"])
end

function x:y()
print(self["face"])
end


In this case, both x:y() and x.y() will print “Punch”.
I’d say that table.innertable.function() is much more object-like than table.inntertable:function(), ie.



local preFunc = function(...) local args = {...} print(args[2] or "No second argument") end

PreMadeTable.SubTable.function["TestValid2ndARG_v2"] = preFunc


I feel much safer doing this and then use a dot :slight_smile:

Those are identical only if you’re gonna call second function only as x:y(). If you’re gonna do this then it’ll behave differently:



local x = {test="A"}

function x.a()
     print(x.test)
end

function x:b()
     print(self.test)
end

local y = {test="B"}
y.a = x.a
y.b = x.b

x.a()
x:b()

y.a()
y:b()