Why not have a "Class" object?

Discussion and feedback on Construct 2

Post » Fri May 10, 2013 6:49 pm

This came to me in a flash of inspiration today. So fast that I didn't even search the forums to see if this has already been suggested, so, if it has, I'm an idiot.

What I realized today is that I can use Sprites (really any object that takes instance variables and can be instantiated) to simulate classes. For example.

I'm making a crude slideshow maker. You place objects on frames and only the objects on the current frame are visible. What I realized is that I could make a Sprite with no image, call it "Frame", and give it whatever instance variables I want. Then I stick its UID in the "frame" variable of each of my objects. This simulates something like:

class Frame {
int value1;
int value2; }

class Object {
Frame frame;

Now instead of "frame" just being an integer (or a row in an array), it points to a robust object that can have its own instances, etc. If I really wanted to get crazy I could even give "Frame" its own specific functions. Inside the Function call, I check if the object being referenced has an existing Frame in its "frame" variable, and if it does, the function proceeds. If not, it doesn't.

And I can create and destroy Frames easily. I can manipulate them better than an array with For Each (ordered).

This is a huge hack. I obviously shouldn't be using sprites for this. So:

Why not make a "Class" object and allow objects to have Class-specific variables (i.e. "Frame frame" above)? Why not then hardcode in Class-specific functions? It would be SO powerful, and it's all within reach.
Posts: 3
Reputation: 781

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 1 guest