Plospo Posted April 23, 2015 Share Posted April 23, 2015 Hi, long time since last post. For starters, the eater component pushes an oneatsomething event, like this: [codesyntax]self.inst:PushEvent("oneatsomething", {food = food})[/codesyntax] Which makes me wonder, is there a way to access the food at the other end? A script that listens for the oneatsomething event, and then checks what kind of food has been eaten, for instance? My guess would be something like this: [codesyntax]self.inst:ListenForEvent("oneatsomething", {food = food}) if event.secondparameter:HasTag("delicious") then (print "yummy" in some way) endend[/codesyntax] I'm very rusty so please have patience, any help is appreciated. Link to comment Share on other sites More sharing options...
Plospo Posted April 23, 2015 Author Share Posted April 23, 2015 Woah for some reason I made 2 duplicate threads + I don't know why that code thingyding isn't working. What is going on... Link to comment Share on other sites More sharing options...
_Q_ Posted April 23, 2015 Share Posted April 23, 2015 You must listen for that event.Then you can use it:self.inst:ListenForEvent("oneat", function(inst,data) self:FoodPoison(data.food) end)function Food:FoodPoison(food) print(food.name) print(food.components.perishable:GetPercent()) self.inst:StartUpdatingComponent(self) self.poisoned = true self.inst:PushEvent("foodpoisonstart")endOther example of this is in kramped.lua file Link to comment Share on other sites More sharing options...
Mobbstar Posted April 23, 2015 Share Posted April 23, 2015 @Plospo, There's a function called ListenForEvent. You must listen for that event.Then you can use it:self.inst:ListenForEvent("oneat", function(inst,data) self:FoodPoison(data.food) end)function Food:FoodPoison(food)print(food.name)print(food.components.perishable:GetPercent())self.inst:StartUpdatingComponent(self)self.poisoned = trueself.inst:PushEvent("foodpoisonstart")endOther example of this is in kramped.lua fileTo clarify what Q means: You can listen for an event as often as you like, and even from instances that aren't the source (you have to give a reference to the source then, though). [article about events]Using an directly constructed/made/declared/whatever function, you can add a call to any other function or variable. It's a bit hack-ey, but who cares? Link to comment Share on other sites More sharing options...
Plospo Posted April 23, 2015 Author Share Posted April 23, 2015 Oh, "PushEvent" was a typo, I meant ListenForEvent. But the method to push "food" into a new function, to be able to use it, was kinda tricky so thanks for the help! I got it all working now. And how the truck do you forum people put up with all these posting options... makes me feel like an old man trying to write an email. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.