Jump to content

If a weapon has a projectile set for it, what's the best way to get info/entries/attributes of the projectile?


Recommended Posts

When a weapon has a projectile set for it, the projectile is saved in the weapon as only a string (the value of which is the projectile's prefab name). When the weapon attacks with the projectile, a new prefab is spawned and thrown.

 

If I have a weapon and I wanna query something from it's projectile (like its speed, or range or something) what would be the best way to do it? One of the only ways I can think that would work for sure would be to actually spawn a prefab and look at it, but that seems messy. 

 

I feel like since the classes are just tables really, the class definitions should just be a master record instance from which other instances are created or something. So I should maybe just be able to look at the class definition instead of needing to spawn one. But I don't really know lua well enough to say the best way. Maybe there's something else. (@simplex, you might be able to help me with this; seems right up your alley)

Link to comment
Share on other sites

  • Developer

When a weapon has a projectile set for it, the projectile is saved in the weapon as only a string (the value of which is the projectile's prefab name). When the weapon attacks with the projectile, a new prefab is spawned and thrown.

 

If I have a weapon and I wanna query something from it's projectile (like its speed, or range or something) what would be the best way to do it? One of the only ways I can think that would work for sure would be to actually spawn a prefab and look at it, but that seems messy. 

 

I feel like since the classes are just tables really, the class definitions should just be a master record instance from which other instances are created or something. So I should maybe just be able to look at the class definition instead of needing to spawn one. But I don't really know lua well enough to say the best way. Maybe there's something else. (@simplex, you might be able to help me with this; seems right up your alley)

Unfortunately I can't currently think of a better way than spawning the prefab.  If you look at 'boomerang.lua' for example, properties like the speed are set on the instance of the prefab and not at the prefab definition itself.  The object definition of a boomerang is a function which sets those properties.

Link to comment
Share on other sites

@dgweber

I also don't think there's a way other than spawning a prefab instance. A prefab isn't really a class, but a prototype specification. And, in prototype-based inheritance, the object itself is what exposes the interface, so you need to get your hands on one.

Link to comment
Share on other sites

 

Unfortunately I can't currently think of a better way than spawning the prefab. properties like the speed are set on the instance of the prefab and not at the prefab definition itself.  The object definition of a prefab is a function which sets those properties.

 

 

@dgweber

I also don't think there's a way other than spawning a prefab instance. A prefab isn't really a class, but a prototype specification. And, in prototype-based inheritance, the object itself is what exposes the interface, so you need to get your hands on one.

 

 

Well I'd say thats pretty unanimous. :D

 

I had forgotten that prefabs arent real classes in DS; that's why I was kind of thinking there may be a better way. I had a good feeling I would have to spawn one and you guys confirmed that. 

 

I haven't worked on this in a little while and Ive been dealing with so many other languages and stuff right now my mind is garbled.

 

Thanks for the help, friends

 

Cheers

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...