Call custom Script through event

Probably a noob question, 

I have a custom class, and want to create an object through event, when event finishes, I want to destroy that object.

Is it possible, if yes how?

I'm using RPG Maker XP right now, if that makes a difference
Well you can, though keeping it alive until the end of the event may be a little more difficult. Ruby's garbage collector will eat your object in some cases, though usually an instance variable will live on. Problem is, since the "Script..." command (Bottom of page 3, I believe) runs by calling Ruby's 'eval' method on your text, I'm not sure instance variables will work. You may want to look into having a class method to start and stop whatever it is you have the code doing.
Depends what you mean by 'destroy'

If you want it to disappear, then you have another page on the event, with no graphic, no commands and conditioned by a self switch.  At the point you want the event to disappear, you activate the self switch.

if that is what you mean, then it is indeed a noob question.  Could I suggest you pause in your game for a short while and work your way through Andar's excellent compilation of info and tips for new users.  You can find it here.  Although it is written for Ace and you are using XP, there are a number of similarities with the way events work, and so you should find it useful.  Taking a bit of time now to familiarize yourself with things will save you a ton of time and frustration in the future.

If that is not what you meant, could you expand a bit on your description of what you want to happen.
Depends what you mean by 'destroy'

If you want it to disappear, then you have another page on the event, with no graphic, no commands and conditioned by a self switch.  At the point you want the event to disappear, you activate the self switch.

if that is what you mean, then it is indeed a noob question.  Could I suggest you pause in your game for a short while and work your way through Andar's excellent compilation of info and tips for new users.  You can find it here.  Although it is written for Ace and you are using XP, there are a number of similarities with the way events work, and so you should find it useful.  Taking a bit of time now to familiarize yourself with things will save you a ton of time and frustration in the future.

If that is not what you meant, could you expand a bit on your description of what you want to happen.
What I mean is this,

I have a class object that I'm passing parameters to, in there there's constructor that will create this object, battlefield map in my example.

When I'm finished the battle, I want to destroy the map created with any variables it used to free up memory.

Then I go on to another battle and it creates a new map and the cycle continues. Does it make more sense?

Just a rough idea:

Code:
event: new object(optional_seed)Class:Constructor:Generate Map Code HereDestroy:Object created when map not needed
My first thought on how to go about this is to use a Module as a data manager. So do something like this:

Spoiler
module MyObjectManager @@my_temporary_object = nil def self.create(params) # do constructor stuff @@my_temporary_object = MyObject.new end def self.destroy # do constructor stuff @@my_temporary_object = nil end def self.my_temporary_object return @@my_temporary_object endend
Then you could make a script call MyObjectManager.create(params) and pass in any parameters in a script call. That would create your object and store in a class variable in the module thereby preserving it as long as you want. You could even access the object later using MyObjectManager.my_temporary_object. Then when you're done. Just call MyObjectManager.destroy and it will free the memory. It's a fairly simple way of achieving what you want. Though I will say that if you're trying to program a complicated new scene, then you're better off following the example of the default scripts and creating a new Scene class and calling it.
Thanks Mobius

Original thread: https://forums.rpgmakerweb.com/threads/call-custom-script-through-event.45649/