Trying to call for the name of a specific object based on certain variables

I have a series of objects ...

obj_big_brick
obj_small_brick
obj_hefty_chair
obj_dead_cat
obj_inflatable_walrus

I want to shoot them out of a cannon. That's the easy part. I could very easily create a button press event that shoots one of them out. No problem.

I also have two variables ...

var descriptor
var thing

I plan on adding a bunch more objects to shoot from the cannon, so I want to make a more simplified system for calling for what object shoots out. However, all of my searches for the right function has come up empty. So I decided to come here and see if I could get help. Here's specifically what I am trying to accomplish.

If var descriptor is 'dead' and var thing is 'cat' then I want to be able to call obj_dead_cat and shoot it from the cannon. The shooting part is easy. I don't need help with that. It's the calling for a specific object based on the variables listed.

Is it even possible? Or do I need to find a better way to do it?
 

Nidoking

Member
I would say "possible, but not recommended". A better way would be to write a function that takes the two strings and returns the correct object index, or making a big map where the keys are the concatenated strings (possibly with "***" between them to prevent collisions from two sets of strings that happen to have the same letters) and the values are the object indices.
 
Ah, thank you all. I have a few things to think about before moving forward but this does lead me in the right direction.
 
Top