Jump to content

Adding a Variable to a Component Class?


Nycidian

Recommended Posts

Is there a way to add a variable to a  class within a component without rewriting the whole thing?

 

Basically what I would like to do is write a new function and using AddComponentPostInit() attache the new function to the component and then add to the class it self the line...

self:NewFunction()

...to initialize the function. 

 

 I just realized there may be another way I can do what I want to do, however I would still like to know if this is possible.

Link to comment
Share on other sites

Alright so this is what I want to do...

 

I am making a mod to record events a character does to do this i need to be able to record events that are not always happening to the character but in the components and prefabs of other things like for example the butterfly getting planted. now I was able to figure out how to do this with the butterflies but using the same method doesn't work for pine cones getting planted.

 

Beyond that I have a feeling its not the best way of doing it also I figured out how to do the same idea with components but again I am afraid its not the best way to to do it. With components i'm overwriting whole functions but it seems to me if I could figure out how to add a line to the class starting a new function that listens for the events already there and sends one to the player it would be better, hence my previous question.

 

Here is the mod as it is now if anyone can at least figure out why the pinecone prefab function doesn't seem to install it would be great 

 

achieve_0.1_working.zip

 

 

These posts are likely confusing I'm sorry I don't know how to explain this better.

Link to comment
Share on other sites

Try something like this:

 

local Deployable = require("components/deployable")local Deployable_Deploy_base = Deployable.Deployfunction Deployable:Deploy(pt, deployer)	local DidDeploy = Deployable_Deploy_base(self, pt, deployer)	if DidDeploy then		if self.inst and self.inst.prefab and self.inst.prefab == "pinecone" then			print( tostring(self.inst).." planted by "..tostring(deployer) )		end	end	return DidDeployend
More universal/robust and way faster than a million PostInits overwriting a million functions.
Link to comment
Share on other sites

Try something like this:

 

local Deployable = require("components/deployable")local Deployable_Deploy_base = Deployable.Deployfunction Deployable:Deploy(pt, deployer)	local DidDeploy = Deployable_Deploy_base(self, pt, deployer)	if DidDeploy then		if self.inst and self.inst.prefab and self.inst.prefab == "pinecone" then			print( tostring(self.inst).." planted by "..tostring(deployer) )		end	end	return DidDeployend
More universal/robust and way faster than a million PostInits overwriting a million functions.

 

Thank you very much 

Link to comment
Share on other sites

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.

×
  • Create New...