A few questions regarding RGSS

Started by Seox, March 24, 2009, 07:16:23 pm

Previous topic - Next topic

Seox

Hiya. I've read several tutorials on RGSS, but have yet to find answers to these questions. Please help me out:

1. Do scripts AUTORUN in the background? On one hand, they couldn't, because windows have to be called (Window.new), but on that same note, how would sprint scripts work? They MUST autorun. Which is the case, and how?

2. I know what def initialize is/does, but what about def main? (I get the define part, just main), and what about def module?

3. I'm trying to make a script that checks to see if anyone in your party is wearing a certain armor. If so, it changes their character sprite. Here is what I have so far:

Spoiler: ShowHide
  def initialize
    for i in 0...$game_party.actors.size
      if $data_actors.armor3_35
        then self.bitmap = $data.actors.character_herohelmetonkv5

Line 4 syntax error. I'm not sure how to set the command to make it change the sprite, and i'm also not sure whether or not to create a class at the top.


Sorry for all the Q's. Thanks a bunch! ^_^

Please and thank you
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

fugibo

March 24, 2009, 07:52:42 pm #1 Last Edit: March 24, 2009, 08:09:42 pm by WcW
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:
Kernel code: ShowHide


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.

Seox

March 24, 2009, 08:22:52 pm #2 Last Edit: March 24, 2009, 09:13:02 pm by Seox
Thank you very much.

I forgot to put "end" on, but I had done it before and it still failed. Testing now.

Does character_name change the graphic, or the name? I need it to change the sprite.

Also, I downloaded blizzard's ebook and I don't understand much of it. I understand all of "the parts of speech", that's what all three of the tutorials that I read taught me. However, NONE of them told me HOW TO ACTUALLY MAKE A SCRIPT. Yes, they were RGSS, and they taught me each and every part of speech and most functions, like that for i in 0... thingity, but not a single tutorial has taught me how to "put everything together"...where can I learn that? Dubealex's came the closest, by walking me through making a window, but now that's all I can do, which is pathetic, and it won't let me do things on the map, make sprint systems, DNS systems, anything for battle, etc. It really pisses me off, because i'm at that stage where I have so many ideas, and I perfectly understand each INDIVIDUAL command, but I don't know how to actually MAKE a script. Where can I learn this???

Also, I understand what "Define" does, what I meant was:
what is the difference between module and class?

EDIT: Also again, I wanna make an item that increases the user's stats. How would I script it so that the target was the one you used it on? I know how to make it actually increase the stat. plzkthx ^_^

Thanks for all of the help ^_^
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

fugibo

March 24, 2009, 09:14:54 pm #3 Last Edit: March 24, 2009, 09:17:01 pm by WcW
The name is stored in @name/actor.name, while the spriteset name is stored in @character_name/actor.character_name. You can find that in the Game_Actor script in the editor.

A "script" can be anything. It just has to define something (class, variable, method, anything.) A typical RMXP script defines a few windows and a scene.

You know what a window is; a scene is any class (whose name typically starts with "Scene_", but doesn't have to) that has an initialize method and a main method. The initialize is obvious; main is called by Main (the script) every time there is a new scene.

So, say you wanted to make a scene with that just exits when you hit X, and does nothing else. The code would just be:


class Scene_DoStuff
  def main
    loop do
      break if Input.trigger? Input::B
    end
  end
end

initiailize is created by default in all classes, so all you have to do is define main. Actually, a better way to define that loop might be:

while (! Input.trigger?(Input::B)) {}

Where ! means "not", which in most programming languages is "the opposite of."

The difference between a module and class is that a module is basically a permanent instance, whereas a class can have instances, but is also an instance itself.

EDIT:
Also, you can look in the "Read this before asking how to script RGSS" thread; Rune's window tutorial, which is linked in there, is pretty good. If you want to see some slightly more advanced features, check out my "Enhanced Default Menu System" in the database -- it has a lot of features and is very well commented, so it shouldn't be that hard to learn some nice tricks from it.

Fantasist

QuoteAlso, I downloaded blizzard's ebook and I don't understand much of it. I understand all of "the parts of speech", that's what all three of the tutorials that I read taught me. However, NONE of them told me HOW TO ACTUALLY MAKE A SCRIPT. Yes, they were RGSS, and they taught me each and every part of speech and most functions, like that for i in 0... thingity, but not a single tutorial has taught me how to "put everything together"...where can I learn that? Dubealex's came the closest, by walking me through making a window, but now that's all I can do, which is pathetic, and it won't let me do things on the map, make sprint systems, DNS systems, anything for battle, etc. It really pisses me off, because i'm at that stage where I have so many ideas, and I perfectly understand each INDIVIDUAL command, but I don't know how to actually MAKE a script. Where can I learn this???

You can only learn this by observing and tinkering the default (or custom-made) scripts. Start with simple things like, say, Scene_End. Then Scene_Menu. You can observe how the control switches from one window to another, how scenes are changed, etc. Then, start experimenting with scripts and try to mod something. See the results, you'll usually get a kick out of it ;)

@WcW: An awful nice job there buddy :up: I wish I could power you up more :)
Do you like ambient/electronic music? Then you should promote a talented artist! Help out here. (I'm serious. Just listen to his work at least!)


The best of freeware reviews: Gizmo's Freeware Reviews




Blizzard

Not to forget that I explicitely said that my e-book wasn't for people who can't script at all. xD
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

fugibo

What Fantasist said -- when it comes to computers, tinkering is always the way to go.


@Blizz: Oops, sorry :P

Seox

Quote from: Blizzard on March 25, 2009, 02:05:46 pm
Not to forget that I explicitely said that my e-book wasn't for people who can't script at all. xD


I know, but that's what doesn't make sense. I've read five tutorials now, all of which repeated the basic "parts of the language" IE methods, classes, etc.

The next step is your ebook. I have yet to find a tutorial which teaches anything in between. It's a dead zone...

I've yet to learn what alias does in a manner which seems at all useful, what instances are, therefore what modules are....etc. When scripts run/how they are called by other scripts, how to make something run, say, automatically when you hit the map, etc.

And nothing teaches them. So. How do people magically script?

XD PARADOX

Anyways. Thanks WcW. *powers up* ^_^
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

fugibo

alias: Copies a method into another method, with a new name. This lets scripters override methods without them disappearing.

instance: An instance is just that, an instance of an object. That is, a class defines a type of object, and an instance is an actual object of that type.

module: Lets you define a static object basically -- its pretty much just an instance without a class. There's more to it than that, but that's what it basically is.

When you start RMXP, all the scripts are loaded in order. They aren't "called."

shdwlink1993

Quote from: Seox on March 25, 2009, 04:22:06 pm
And nothing teaches them. So. How do people magically script?


People usually magically script by checking the main resource, the Scripts themselves, and observing them and/or tinkering around with them. If you don't understand why something's there or what it does, see what happens when it's not there, just random stuff like that.

An interesting side note is that almost every single script on this website is really just someone's tinkering that got them something unique and interesting (or what they THINK is unique and interesting enough to share).
Stuff I've made:




"Never think you're perfect or else you'll stop improving yourself."

"Some people say the glass is half full... some half empty... I just wanna know who's been drinking my beer."

Seox

March 25, 2009, 05:04:08 pm #10 Last Edit: March 26, 2009, 11:38:57 am by Seox
Quote from: shdwlink1993 on March 25, 2009, 04:45:17 pm
Quote from: Seox on March 25, 2009, 04:22:06 pm
And nothing teaches them. So. How do people magically script?


People usually magically script by checking the main resource, the Scripts themselves, and observing them and/or tinkering around with them. If you don't understand why something's there or what it does, see what happens when it's not there, just random stuff like that.

An interesting side note is that almost every single script on this website is really just someone's tinkering that got them something unique and interesting (or what they THINK is unique and interesting enough to share).



Hah...I get it, perfectly, and that makes much more sense than my crazy conspiracy theory involving penguins. XD

Thanks, everyone! ^_^


Edit: is there a way to specify a wildcard?
Ie: if @active_battler.weapon.description == wildcard + 'sword',
Then.,,



That way, any description ending in sword would work.

Also, having trouble with @active_battler.weapon_id
It says undefined method, yet is used at least 60 times with all other scripts.
I'm trying to do:
    case @active_battler.weapon_id
          When 1...
Etc

So that when certain weapons are equipped, certain things happen. Little help?

Also, I get what alias DOES, but can't think of a single situation where it would be useful. Why not just define a new method?

Please and thank you.
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)

fugibo

It's "when", not "When." Ruby is case-sensitive.

For the wildcard thing, you'd need to learn REGEXP, or regular expressions. Zeriab has a tutorial on this forum, I think.

"alias" lets you rewrite a method and keep the old one. You can't define a new method without rewriting other scripts to call that method instead, so you just rewrite the current one with alias.

Seox

March 26, 2009, 05:33:08 pm #12 Last Edit: March 26, 2009, 07:24:07 pm by Seox
Quote from: WcW on March 26, 2009, 03:54:53 pm
It's "when", not "When." Ruby is case-sensitive.

For the wildcard thing, you'd need to learn REGEXP, or regular expressions. Zeriab has a tutorial on this forum, I think.

"alias" lets you rewrite a method and keep the old one. You can't define a new method without rewriting other scripts to call that method instead, so you just rewrite the current one with alias.


I think I remembet trying to find that tut, but it gave me a 404, o' doom.

Ok, so you mean to say that, without alias, scripts would need to be rewritten AS WELL? Alias just allows you to sort of "add on" by rewriting, in the sense that it also preserves the initial method, but keeps the name so that it works just the same?

If that is the case, then is there any way that I can fix certain script incompatibility using alias?

EDIT: So I'm modding certain things and making a script for a radio (as in the military kind). How do I use the Window_InputNumber? I tried, and it displays the number but I can't in any way interact with it, even by going

def frequency #s1, menu_index=0
  $game_system.se_play($data_system.decision_se) #play an SE
  @window_a1.active = false
  @window_frequency.active = true

The first is the normal menu, and the winow_frequncy is the numberinput thingity.

Thank you ^_^
... (<<<<<<<<<<<<<<< TEH DOTS OF DOOM. Hey, kinda catchy. :naughty:)