2015-06-24 20:00:27

Hello all, its me again.
So, I was reading on classes in the bgt manual, attempting to look at ways of adding items to all my titles.
I understood constructors and classes somewhat decently, though, destructers I really am not sure of since there was maybe a paragraph written on destructers.
So, say I wanted to destroy a specific enemy after the player killed it, how would I do that?
I get the idea of creating them, destroying them is a bit difficult to me. Thanks all!

2015-06-25 03:28:06

A destructor is a function that gets called immediately before your class is destroyed (removed from memory).
In general programming you'd usually use it to do such things as close files, database or network connections or other resources your class might have created during it's lifetime. To be honest it's not too often that you'll have to do any kind of explicit teardown in BGT. To declare a destructor for a class called test, you do the following:
~test()
{
//code you want to run before your instance dies goes here.
}

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.

2015-06-25 03:31:52

So then, let us say if we have a game board that is 100 by 100.
On this board are 50 items. How would I then destroy the object that belongs to just that one item?

2015-06-25 05:26:24

Can you give a bit more information about how your board and your items are implemented? Generally speaking it's just a matter of deleting an item in an array... but depending on the way the game has been designed there might be another step like changing some property of another object to tell a different part of your game about the loss of your item.

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.

2015-06-25 05:37:19

I hadn't actually gotten around to putting that in, its just the thought of destructers that confused me so much, I suppose I was just overlooking it, as I always do.

2015-06-25 06:19:08

What specifically confuses you about the concept of a destructor? Destructors in BGT have incredibly few use cases because it's a completely managed development environment where all the housekeeping is done for you behind the scenes. The garbage collector takes care of freeing up any resources that might have been borrowed from the operating system in order to create your object.
The only use case I can think of is this: perhaps your game uses something like sound pool (for instance), and your class, which is an enemy, inserts it's sound in to the pool when it gets created (by the destructor). Now when the enemy is defeated by the player (or otherwise no longer needed), perhaps you might implement a destructor which remove's the enemy's sound from the pool and maybe even plays it's death sound. There it's being used as a convenience feature but it doesn't have the implications it does in more conventional programming wherein resource allocation and deallocation is a concern.

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.