Can a component have a component? Need help figuring out a solution for this
by Brandon · in Torque X 2D · 01/20/2009 (12:08 pm) · 4 replies
So I want to have different weapons that shoot different projectiles with different hit points and all of that.
So obviously I somehow need to make my items carry this information. I was thinking maybe I could add a component to an item component itself.. but I don't know
SO what is the best way to do this?
Should I just have an item type and then if then else my way through the item types and send the appropriate data to the event? So like if it's a weapon type 1 i sent the hit points and whatever else to the fireweapon event and in that event I just change the information in the player weapon component?
Which means for every possible item I have to add that component to the player and in the fire event change the properties of the component then call it's usage function?
If any of that makes sense.. Thanks
So obviously I somehow need to make my items carry this information. I was thinking maybe I could add a component to an item component itself.. but I don't know
SO what is the best way to do this?
Should I just have an item type and then if then else my way through the item types and send the appropriate data to the event? So like if it's a weapon type 1 i sent the hit points and whatever else to the fireweapon event and in that event I just change the information in the player weapon component?
Which means for every possible item I have to add that component to the player and in the fire event change the properties of the component then call it's usage function?
If any of that makes sense.. Thanks
#2
01/20/2009 (2:36 pm)
Do you have the TX Book? There is a whole bunch of info on this in chapter 9.
#3
I think I realized I don't need to process tick in this component because basically once this component becomes active it means a player has picked it up. So the players ProcessTick can be used for timing for what I'm trying to do.
I think I just have to think out loud on these forums haha.
What I ultimately did was put a Weapon component on the pickup item in TXB and added an item type. So now based on the item type my add item method in the inventory manager will Look for the component on the "ourObject" and add it to the inventory item itself. So when I use the item it digs down and figure out what component is installed and fires it.
This allows me to configure all sorts of pickupable items in the TXB. Which my initial purpose is to have multiple weapons with different projectiles and hit powers and etc..
Let me know if anyone has a better idea to implement this. I might be making things difficult heh.
01/20/2009 (2:52 pm)
Yeah I have it but not with me at the moment.I think I realized I don't need to process tick in this component because basically once this component becomes active it means a player has picked it up. So the players ProcessTick can be used for timing for what I'm trying to do.
I think I just have to think out loud on these forums haha.
What I ultimately did was put a Weapon component on the pickup item in TXB and added an item type. So now based on the item type my add item method in the inventory manager will Look for the component on the "ourObject" and add it to the inventory item itself. So when I use the item it digs down and figure out what component is installed and fires it.
This allows me to configure all sorts of pickupable items in the TXB. Which my initial purpose is to have multiple weapons with different projectiles and hit powers and etc..
Let me know if anyone has a better idea to implement this. I might be making things difficult heh.
#4
Anyway, if your solution is working well for you then it's the best implementation. In general I like TX Book method as it's pretty flexible.
01/20/2009 (2:57 pm)
I know what you mean about thinking out loud, so to speak. Most of the time I figure out my problem just in typing it out here. If it weren't so damn cold here I'd be on my usual "go for a run and you'll just figure it out" -- it's good for me AND I get work done.Anyway, if your solution is working well for you then it's the best implementation. In general I like TX Book method as it's pretty flexible.
Torque Owner Brandon
cod3r on irc
So I can create a new component say a weapon component and add it to my item I just picked up. And access it from item.component. The only thing I'm struggling with now is how to register it so that the ProcessTick is called.
If I add a weapon component to my pickup item and add the pickup items weapon component to my item on add inventory. I can use it so long as I don't delete the pickup item from the scene.. my item weapon component processes it's ticks.
So is there a way to register components that are not part of drawn objects?