2015-01-26 11:36:26

I have an interesting bgt question:
If I have for example a class called enemy
And I make a subclass like this: Class spaceship : enemy and another called class tank : enemy;
Can I then make an array of enemies enemy[] enemies; and put both tanks and spaceships?

Thanks!

ReferenceError: Signature is not defined.

2015-01-26 11:55:51

Yes. That's exactly how it works. smile

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-01-26 15:12:12

Oh, I am relieved. I didn't think you could do that for some reason. That's very nice big_smile

ReferenceError: Signature is not defined.

2015-01-26 15:29:45

Also, congratulations on discovering polymorphism without being told about it.  From where I'm standing, that's exactly what you just did.  And most programmers don't get it for a very long while even when it's explained (I fell into this category, many a year ago).

My Blog
Twitter: @ajhicks1992

2015-01-27 00:14:48

Yeah, actually polymorphism is explained in the bgt language tutorial. It is a beautiful thing once you figure it out. I wish bgt subported abstract classes though. They seem pretty cool, because they force you to conform to a syntax. Basically so you don't miss something when you define your subclasses. That's what I learned about in java.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2015-01-27 02:24:35

Hi,
I knew about this feature of bgt, but in the sort of minigames I am creating right now in it, I don't really need it for much as of right now. I can see it coming in very useful later on, though.

2015-01-27 02:33:59

I'm not sure if you'd necessarily need anything abstract classes provide that you can't get with interfaces, unless it's variables?

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-01-27 17:28:37

Hi,
PureBASIC allows you to do this too. You can do something similar, but not like int num_enemies[] enemies;. Instead, you define a structure like so:
Structure enemy
name.s
x.l
y.l
z.l
type.s
EndStructure
Then, wherever you like, polymorph it like so:
Dim enemies.enemy(0)
This is how DMPA and several of Reality Software's games work.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.
My Github

2015-01-27 17:51:59 (edited by camlorn 2015-01-27 17:54:17)

Where is the inheritance in your Purebasic example?  And why is Purebasic coming up, anyway?
The whole point of polymorphism is not variables, it is class methods.  You cannot do polymorphism without very interesting pointer tricks in languages that do not provide built-in support for classes.  You can do giant ugly switch statements and if trees based on a type field, but the whole point here is that inheritance and polymorphism get rid of said switch statements and if trees, splitting your code into something that's manageable and can be considered in isolated chunks.  They also let you add new fields to your subclasses, i.e. Enemy versus NamedEnemy.  And now we're both off topic, I guess.

My Blog
Twitter: @ajhicks1992

2015-01-27 21:33:12

yep cae, I would love to be able to put variables in interfaes. Basically I am forced to make accessor and mutator methods instead.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2015-01-29 14:49:13

Yeah... I always keep forgetting to check the bgt tutorial. Thanks to that I also learned about interfaces, that is what my new game is using big_smile

ReferenceError: Signature is not defined.