• ENT:StartTouch
    12 replies, posted
So I am here again the [I]"Noob"[/I]. 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 [B]Init.lua[/B] [CODE]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[/CODE] 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. [B] Any help would be amazing[/B]
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: [code] 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 [/code] literally removed just three lines. Alternatively you can use [I]elseif[/I].
or rewatch Code Blue's video.
[QUOTE=whitestar;51123299]or rewatch Code Blue's video.[/QUOTE] you only know that because you help me before and I mentioned it [editline]28th September 2016[/editline] [QUOTE=Kiro The Pro;51123266]Try to learn arithmetics and some general logical puzzles before/during learning how to lua <3 Also, how about: [code] 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 [/code] literally removed just three lines. Alternatively you can use [I]elseif[/I].[/QUOTE] Thanks was being dumb before asking question and didn't fully understand StartTouch
Shouldnt it be ENT:StartTouch instead of ENT.StartTouch ?
I see
[QUOTE=Mrdbuffalo;51125863]You put the same thing But the script works now[/QUOTE] Not the same thing. Notice the ":" and the "."
[QUOTE=geferon;51126131]Not the same thing. Notice the ":" and the "."[/QUOTE] yup thanks
: is for dynamic functions . is for more static functions Alternatively, you can't use the self variable in static functions.
[QUOTE=Potatofactory;51127372]: is for dynamic functions . is for more static functions[/QUOTE] Eh not really, the only thing ":" does is implicitly declare "self" argument. It's just a syntactic sugar. These are identical: [code] function x.y(self) end function x:y() end [/code]
[QUOTE=mijyuoon;51127444]Eh not really, the only thing ":" does is implicitly declare "self" argument. It's just a syntactic sugar. These are identical: [code] function x.y(self) end function x:y() end [/code][/QUOTE] To be exact, these* are identical [code] x = {} x["face"] = "punch" function x.y() print(x["face"]) end function x:y() print(self["face"]) end [/code] In this case, both x:y() and x.y() will print "Punch". I'd say that [I]table.innertable.function()[/I] is much more object-like than table.inntertable:function(), ie. [code] local preFunc = function(...) local args = {...} print(args[2] or "No second argument") end PreMadeTable.SubTable.function["TestValid2ndARG_v2"] = preFunc [/code] I feel much safer doing this and then use a dot ^_^
[QUOTE=Kiro The Pro;51127570]To be exact, these* are identical [code] x = {} x["face"] = "punch" function x.y() print(x["face"]) end function x:y() print(self["face"]) end [/code] [/QUOTE] Those are identical only if you're gonna call second function only as [I]x:y()[/I]. If you're gonna do this then it'll behave differently: [code] 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() [/code] [url]http://ideone.com/CCPlzz[/url]
Sorry, you need to Log In to post a reply to this thread.