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)

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

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

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...