1) Scripts are loaded consecutively in the same order they are in the script editor. They don't "autorun," they define classes and methods, then the last script (Main) launches the game.
2) The "def" command creates a method. A method is just an action that an object (or "class") can perform. "def initialize" defines the "initialize" method, which is called every time you use .new. "def main", on the other hand, defines the "main" method. This isn't a special method, and doesn't do anything until it is called. However, the "Main" script mentioned above automatically calls that one for each $scene.
3) In Ruby, all blocks have to be closed by an "}" or "end". This means that every time you use the "def" command, you have to close it with "end"; the same goes for "if", "for", and others. Since you aren't closing your blocks, you're getting an error.
Also, the "for i in 0..$game_party.actors.size" statement is very slow; instead, you should use "$game_party.actors.each do |actor|".
So, the code that you have should look like this: (use [code]blah blah[/code], btw)
What your code should look like: ShowHide
$game_party.actors.each do |actor|
if actor.armor2_id == <whatever_id_you_want>
actor.character_name = <whatever_name_you_want>
end
end
Okay, this code doesn't have a "def initialize" for a reason -- you only use that when you are defining an object. However, all you want to do with this code is change the spriteset for any actor who is wearing a certain armor -- you don't need an object for that. You could just put this in a "Call Script" command (it'd be better to but it in a Kernel method, but I'll explain that later on.)
We just go straight to the code here; we begin by
iterating through $game_party.actors, which is the list of all actors in the current party.
Iterating is just moving through a list (also known as an
array.) The "do |actor|" part is called a
block. A block is a piece of code the can be executed multiple times depending on the scenario. The "do" command starts the block; the "|actor|" part tells Ruby to give it an item from $game_party.actors each time it executes the block and store it in the variable "actor." Together with the "each" method, this means that everything between that line and the closing "end" will be executed for each actor, and that actor can be accessed from the "actor" variable.
On the next line, we use an "if" statement. These do not have to use a "then" statement, and even though it won't hurt if you do use one there's no point in it, so don't. The "if" checks to see if the ID of the Actor's current armor (stored in "actor.armor2_id") matches the desired ID (replace the <whatever_id_you_want> part with that ID, ie 17). If it does, it will execute it's block of code below; if not, it will just skip over it.
The last line of code (everything else is just an "end" to close blocks) is simple: it just changes the name of the actor's spriteset to the desired name (once again, replace the <..> stuff with that.) Note that one = means "is", while == means "equals."
To execute this code, I'd recommend you add it as a method in Kernel. "Kernel" is a module whose methods can be called anywhere, in any script. This makes it easier for you to use it in, say, a "Call Script" command. Here's an example, which will define the "change_sprite_if_armor" method to your new code, so that you can use it anywhere:
module Kernel
def change_sprite_if_armor
$game_party.actors.each do |actor|
if actor.armor2_id == <whatever_id_you_want>
actor.character_name = <whatever_name_you_want>
end
end
end
If you add this as a script, you will be able to type "change_sprite_if_armor" in as a script command and it should work.
Sorry if I'm not clear; the best way to learn is by reading Blizz's e-book, which you can find on this forum.