C
Carpe Zythum
Guest
I truly do miss some features of OOP languages. I'm having a problem implementing a modular upgrade system for my game in Game Maker.
I have a GUI object "+", and I want to be able to upgrade several aspects of my tower. Ex: max hit points ( soul ), damage, etc.
The problem is, I want to abstract this functionality. I'd like to be able to send a "pointer", ( a reference ) to a field in my Tower class to this button so it can update the variable.
This way, I would save me a lot of unnecessary lines of code.
The only solution (using the resources in GMZ ) I came up with is passing a string name of the field I want to change, and then using a switch statement to find the appropriate field in the Tower object.
Or is there a way to do something like javascript can do ex: object["instance_variable"] = value?
I have a GUI object "+", and I want to be able to upgrade several aspects of my tower. Ex: max hit points ( soul ), damage, etc.
The problem is, I want to abstract this functionality. I'd like to be able to send a "pointer", ( a reference ) to a field in my Tower class to this button so it can update the variable.
Code:
...
// Create the GUI button for upgrading tower's soul ( hit points )
soul_increase = instance_create(topx + 210, topy + 58, obj_plus);
with(soul_increase) {
amt = 10; // The amount the + button should increase
controll_var = * (pointer to, is it possible though?) tower_instance.soul;
}
damage_increase = instance_create( ..., obj_plus );
with(damage_increase) {
amt = 3.2;
controll_var = * tower_instance.damage
}
...
The only solution (using the resources in GMZ ) I came up with is passing a string name of the field I want to change, and then using a switch statement to find the appropriate field in the Tower object.
Or is there a way to do something like javascript can do ex: object["instance_variable"] = value?