RPG Maker VX Ace

RPG Maker VX Ace

View Stats:
Resi ♥ Jun 19, 2015 @ 4:43pm
Creating a method to call via scripts
So I'm just looking for the simplest possible way to do this so I can not worry so much about spending infinite hours doing something I shouldn't. Essentially, I'm just checking and assigning game_variables along with removing party items. I've been messing around with figuring it out, but I don't really understand defining a proper method to call it and I end up with a variety of errors that confuse me.

If I had something like:
if $game_variables[183] == 170 if $game_variables[199] == 2 $game_party.gain_item($data_items[170], -1) $game_variables[183] = 12 else $game_variables[183] = 1 end end
in the script editor, what would I have to do to make it so I can call the script via an event?

I do not and can not use the Script... event and paste the above inside of it as it's not as simple as that.
< >
Showing 1-7 of 7 comments
Cryptic Jun 19, 2015 @ 4:46pm 
Let me ask, why isnt it so simple?
Resi ♥ Jun 19, 2015 @ 4:50pm 
If I did this via eventing means it would take me over 2 months to complete one mechanic I'm looking to implement.
Kio Kurashi Jun 19, 2015 @ 4:56pm 
First let me explain what a method is. It is the defined structure of command that a class or module can execute. Sometimes it just contains a little bit of code like a Hp value.

Now to look at the code you have given us. The way I see it read is like so:
If GV 183 is 170 then I'll check to see if GV 199 is 2. If it is then I'll remove 1 of item number 170 from the party. If it isn't then I'll set myself (GV 183) to 1.

This means that unless the 183 = 170 you will do nothing at and if it is then 183 wil end up at either 12 or 1. Then of course if 199 = 2 the parrty loses 1 of item 170.

if this is what you want to happen then I would say to make a class to define it in. We do this with the line 'class My_Class'. After we have done thatthen we must define what our class will do. This is acomplished by the line 'def my_Method'. Each of those lines will need their own End tags. I see that you already understand what those are and how they basically work. Within the method we defined is where we will put the code you have created. I have no idea if that is how you actually want it set up, but that is probably because I have no idea what you are doing.
Here is an example of what we have
class My_Class def my_Method if $game_variables[183] == 170 if $game_variables[199] == 2 $game_party.gain_item($data_items[170], -1) $game_variables[183] = 12 else $game_variables[183] = 1 end #GV 199 end #GV 183 end #my_Method end
Now inorder to call this within the script editor we would need to create the instance of the class like so:
@instance_class = My_Class.new

Unfortunatly all that does is create the class to call the method we would then add the following line after it (within the same script call command)
@instance_class.my_Method

Now your method has been called and the code has been parsed. If you want to check where your information ended up you can use msgbox commands
class My_Class def my_Method if $game_variables[183] == 170 if $game_variables[199] == 2 $game_party.gain_item($data_items[170], -1) $game_variables[183] = 12 msgbox("Item Removed") else $game_variables[183] = 1 msgbox("Variable 183 set to 1") end #GV 199 end #GV 183 msgbox("my_Method has completed it's run") end #my_Method end

These will pop up a little box with the information inside the ( ). I cannot remember right now whether or not the " " are required. It is I tested it

This is all nice and all but what if I told you that we could make a small change and be able to run the code with a single line in the script call? Well we can! Every class will have a method called initialize. Wheather we define it or not it's there. The thing about the initialize method is that it is run as soon as the class is... well initialized. Clever Ruby huh? So the way we make it run our code on start up is simple. We add this:
def initialize my_Method end

This means that it will run that method as soon as it is created.
So now we have:
class My_Class def initialize my_Method end def my_Method if $game_variables[183] == 170 if $game_variables[199] == 2 $game_party.gain_item($data_items[170], -1) $game_variables[183] = 12 msgbox("Item Removed") else $game_variables[183] = 1 msgbox("Variable 183 set to 1") end #GV 199 end #GV 183 msgbox("my_Method has completed it's run") end #my_Method end

Now all we need is to use @instance_class = My_Class.new to get the code to run.

That's all for now because I need to go and get myself some food :P
Last edited by Kio Kurashi; Jun 19, 2015 @ 5:19pm
Resi ♥ Jun 19, 2015 @ 5:36pm 
So I've tested that out, thank you Kurashi for the simple explanation, but I still come across an error.

http://i.imgur.com/8D2Txhw.png
Undefined variable or method for summer_Check, which is my_Method

I've added you so I can explain my process a bit more indepth as I don't want to really give away what I am doing publicly.

Oh I seem to have misread the last bit and I should be running the class, not the method. One moment as I test this.

Okay, this works absolutely perfectly. Thank you so much Kurashi. You can still accept my request if you'd like to know what I'm working on.
Last edited by Resi ♥; Jun 19, 2015 @ 5:39pm
Cryptic Jun 19, 2015 @ 7:07pm 
Kurashi is a genie. I'm telling you.
Kio Kurashi Jun 19, 2015 @ 9:11pm 
Originally posted by {=Corrosion=}:
Kurashi is a genie. I'm telling you.
:shantae_smile:
Cryptic Jun 19, 2015 @ 9:39pm 
Originally posted by Kurashi:
Originally posted by {=Corrosion=}:
Kurashi is a genie. I'm telling you.
:shantae_smile:
Belly dancer time.
< >
Showing 1-7 of 7 comments
Per page: 1530 50

Date Posted: Jun 19, 2015 @ 4:43pm
Posts: 7