Call custom Script through event

lordcorvin

Villager
Member
Joined
Oct 6, 2015
Messages
8
Reaction score
0
First Language
English
Primarily Uses
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
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
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.
 
Last edited by a moderator:

lordcorvin

Villager
Member
Joined
Oct 6, 2015
Messages
8
Reaction score
0
First Language
English
Primarily Uses
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
 
Last edited by a moderator:

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
My first thought on how to go about this is to use a Module as a data manager. So do something like this:

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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top