Accessing "Variable Definitions" of an object type which currently has no instances

b-wb

Member
Hey all,

First time posting on here, I frequently find what I need by searching other people's questions, but haven't found anyone else trying to do this just yet.

I'm working on a top down space flight game with controls similar to Atari's Asteroids but modular space ships made up of multiple objects. Ships spawn with a number of attached "addons" including weapons and thrusters, and these addons respond to the ships' controls.

As I build AI for computer pilots, I want them to have a rough idea of how far their weapons ranges are. Ideally, they would be able to tell what the ranges of all weapons were and fire each separately, but I'm not at that point yet. Currently, I'd be happy to find the longest range weapon and save that weapon's range as a single variable, say weapon_range

All ships fall under one parent object, par_starship, and all addons fall under one parent object, par_addon. There are parents under that category as well, such as, in this case, par_projectile_weapon. Each projectile_weapon object is defined with an object type as its projectile-- one type of blaster bolt may act differently from another. So to clarify:

-A starship creates projectile weapons
-The projectile weapons create projectiles
-The projectiles, in their variable definitions section, have defined speeds and lifetimes, which can be multiplied to find their ranges

My problem is this: is there a way that I can, immediately after spawning any given projectile weapon, send the maximum range back to the starship? What I want to do is search the value stored in the object type for the projectile and report that, regardless of the fact that no such projectiles exist during the first frame of the game.

Of course, I know there are other solutions, but I am hoping to avoid significant re-factoring unless there's a good reason for it. If there is a way to access the variable definition of an object, not a particular instance, then that's what I'm looking for!

Thank you in advance for considering my issue :) Many of you have already been a great help to me just by answering questions that I share with other, previous posters.

Wishing you well!
 

Nidoking

Member
I just make a ds_map of object indices to values, and then you can replace all of the Variable Definitions with value = value_map[? object_index]
 

b-wb

Member
Create one instance of each and then deactivate them. You can read variables from deactivated instances.
Thank you, at work right now but will try this next time I get coding.


I just make a ds_map of object indices to values, and then you can replace all of the Variable Definitions with value = value_map[? object_index]
Sounds interesting. Why do you prefer this? I'm not sure I see the advantage, but then, I'm not thinking too hard about it. It's okay if you don't want to explain further.
 

Nidoking

Member
Sounds interesting. Why do you prefer this? I'm not sure I see the advantage, but then, I'm not thinking too hard about it. It's okay if you don't want to explain further.
I'm used to working in languages where it's possible to attach a variable to the equivalent of an object, rather than to an instance of that object. I don't want to have to create an instance to get information about its type. Mapping object indices to values is a bit cumbersome, but it serves that purpose. I can use the object index to get the variable value, and I don't need to have an instance to do it. Deactivated instances have to be managed carefully - a map in my Controller object follows me throughout the game, and it's always there when I need it.
 

b-wb

Member
I'm used to working in languages where it's possible to attach a variable to the equivalent of an object, rather than to an instance of that object. I don't want to have to create an instance to get information about its type. Mapping object indices to values is a bit cumbersome, but it serves that purpose. I can use the object index to get the variable value, and I don't need to have an instance to do it. Deactivated instances have to be managed carefully - a map in my Controller object follows me throughout the game, and it's always there when I need it.
Neat, that makes sense. Thanks for explaining.
 
Top