The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: magusbrother on September 08, 2007, 06:22:22 AM

Title: [Resolved]How can I add windows in my Battle Scene?
Post by: magusbrother on September 08, 2007, 06:22:22 AM
I've been editing my script recently. I want to know how put two windows in the battle scene. The first is to the right which displays the characters' status, and I've got this solved. The other one is beside the first one which holds the monsters name and the number of monsters. Help me please.
Title: Re: How can I do this?
Post by: Falcon on September 08, 2007, 12:51:43 PM
1. Read the damn Rules, that's Strike 1 for you.
2. Give a meaningful topic title.

http://rmrk.net/index.php/topic,20694.0.html
Title: Re: How can I do this?
Post by: J-Crew on September 08, 2007, 06:57:34 PM
@Falcon: Are you ever gonna help anyone again or is this gonna become a regular thing?  :tpg:
Title: Re: How can I do this?
Post by: Falcon on September 08, 2007, 07:31:35 PM
I don't help those who break rules.
Title: Re: How can I do this?
Post by: Kokowam on September 08, 2007, 08:08:48 PM
He may eat me, but he loves screwing noobs.
Title: Re: How can I do this?
Post by: Falcon on September 08, 2007, 08:21:59 PM
I don't screw n00bs, I perfer to tell them to go fuck themselves.

AND NOW SHUT UP AND STAY ON TOPIC.
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 09, 2007, 12:12:36 AM
I'm sorry to break the rules. ;9 I edited my topic and you moved it, I hope there's nothing wrong. I hope I can get  my help soon.
Title: Re: How can I add windows in my Battle Scene?
Post by: Falcon on September 09, 2007, 01:09:59 AM
Don't worry about it, just do your best to make sure it doesn't happen again :)

I'll see what you would do about the window later, I think I know how it would work.
Title: Re: How can I add windows in my Battle Scene?
Post by: Sophist on September 09, 2007, 03:20:01 AM
Quote from: Falcon on September 09, 2007, 01:09:59 AM
Don't worry about it, just do your best to make sure it doesn't happen again :)

I'll see what you would do about the window later, I think I know how it would work.

Schizophrenic.
Title: Re: How can I add windows in my Battle Scene?
Post by: Falcon on September 09, 2007, 12:41:38 PM
No, I just pull the good cop/bad cop routine by myself.
Title: Re: How can I do this?
Post by: Irock on September 10, 2007, 05:20:58 PM
Quote from: mastermoo420 on September 08, 2007, 08:08:48 PM
He may eat me, but he loves screwing noobs.
I wonder why he didn't screw you then. :333
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 11, 2007, 07:20:35 AM
Please stay on the topic.

Get used to stuff like this happening in your topic, it happens all the time.
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 14, 2007, 07:16:10 AM
Does anybody would like to help me?
Title: Re: How can I add windows in my Battle Scene?
Post by: Shinami on September 14, 2007, 06:26:59 PM
Quote from: magusbrother on September 08, 2007, 06:22:22 AM
I've been editing my script recently. I want to know how put two windows in the battle scene. The first is to the right which displays the characters' status, and I've got this solved. The other one is beside the first one which holds the monsters name and the number of monsters. Help me please.
The window that displays the character's status and what not is already made for you. If you wish to edit it, look at Window_BattleStatus. The second one is easy enough. All you need to do is pass off @troop_id as an argument to your new window. Below is an example.


class Window_MonsterName

  def initialize(troop_id)
    super(x, y, width, height)
    self.contents = Bitmap.new(width - 32, height - 32)
    @troop_id = troop_id
    refresh
  end

  def refresh
    self.contents.clear
    for e in $game_troop[@troop_id].enemies.size
      self.contents.draw_text(x, y*e, width, height, $game_troop[@troop_id].enemies[e].name)
    end
  end
end


That's an example and it is untested but that should point you in the right direction. If the $game_troop methods I called are off, then look around the Game_Troop class to find the right methods to call to make it work.
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 14, 2007, 11:44:08 PM
I'm sorry; I'm just a novice when it comes to scripting. I don't know what must happen next when I input the script.
Title: Re: How can I add windows in my Battle Scene?
Post by: Shinami on September 15, 2007, 05:53:14 AM
My previous post was more or less a how-to set of instructions. I'm guessing that you're pretty much completely new to scripting. Okies. This post of mine breaks down the way a window works. (http://rmrk.net/index.php/topic,14366.msg205369.html#msg205369) That should teach you a good bit about windows.

Quote from: magusbrother on September 14, 2007, 11:44:08 PM
I don't know what must happen next when I input the script.
Quite simple. You want to call a window so what do you do? If you don't know how to make a window appear, then look at the method called "main" inside the Scene scripts. You should see something like these examples.

@actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])
@gold_window = Window_Gold.new
@help_window = Window_Help.new
@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
Now...what does each of those examples have in common? The window being called is stored within a public variable aka @variable that can used through out the entire class. Another key thing they have in common is that all windows being stored in a variable has the .new method being called. This tells RGSS that you want to make a new window.

If you're still unclear on how to do something involving windows, you know where to find me.  :blizj:
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 15, 2007, 11:54:41 AM
I'm getting an error in @monster_name = Window_MonsterName.new. I might have missed something or I got it wrong. It says that it has wrong number argument.
    # Make other windows
    @party_command_window = Window_PartyCommand.new
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.visible = false
    @status_window = Window_BattleStatus.new
    @message_window = Window_Message.new
    @monster_name = Window_MonsterName.new
Title: Re: How can I add windows in my Battle Scene?
Post by: Shinami on September 15, 2007, 03:42:23 PM
Now I'll get to go a little more indepth with windows. Look at the first and last examples in my last post. Those two have something AFTER the .new syntax. These are called "arguments". An argument is basically information passed on. In this case, you will want to pass on the argument @troop_id. Why are we using @troop_id? Scene_Battle stores the monsters you are going to fight inside @troop_id and you're wanting to have a window list the monster names so it makes sense that you'd pass off the information of the monsters you're fighting as an argument to the window.

This is a window being called with a single argument.
@window_status = Window_Status.new(actor.id)

This is a window being called with two arguments.
@window_status = Window_Status.new(actor.id, @window_command.index)

If you're going to pass off an argument in the calling of a window, scene, or class method then you'll also need to have the same number of arguments. I'll use Window_MonsterName as an example. Lets look at the initialize method of WIndow_MonsterName.

def initialize(troop_id)Hmmm...I see an argument called troop_id. Remember that error you posted about? Well that's what happens when you supply the wrong number of arguments when you call something regardless of it being a window, scene, OR class method. In this case, you tried calling a window that has an argument in the initialize method without supplying something as that argument when you called the window.

@monster_name = Window_MonsterName.new(@troop_id)This is what you should have used when you tried calling Window_MonsterName. We now have an argument supplied to the window when it's called.
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 16, 2007, 12:22:10 AM
I've got the rest resolved. I changed something in the script you gave me. I'm still getting errors.
  def refresh
    self.contents.clear
    for e in $data_troops[@troop_id].members.size
      self.contents.draw_text(x, y * e, width, height, $game_troop[@troop_id].enemies.name)
    end
  end
end

(for e in $data_troops[@troop_id].members.size) I'm getting an error in this line. It says that undefined method 'each' for 3:FixNum

I'm sorry; I'm asking to much... ;9
Title: Re: How can I add windows in my Battle Scene?
Post by: shaz on September 16, 2007, 03:48:20 AM
You made some errors in your modifications.

Quote from: Shinami on September 14, 2007, 06:26:59 PM


class Window_MonsterName

  def initialize(troop_id)
    super(x, y, width, height)
    self.contents = Bitmap.new(width - 32, height - 32)
    @troop_id = troop_id
    refresh
  end

  def refresh
    self.contents.clear
    for e in $game_troop[@troop_id].enemies.size
      self.contents.draw_text(x, y*e, width, height, $game_troop[@troop_id].enemies[e].name)
    end
  end
end



You could try

for e in $game_troop.enemies.size
  self.contents.draw_text(x, y*e, width, height, $game_troop.enemies[e].name)
end

and see if it makes a difference.
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 16, 2007, 05:20:56 AM
It doesn't make any difference. There is something wrong in the line I posted.
Title: Re: How can I add windows in my Battle Scene?
Post by: Shinami on September 16, 2007, 05:34:59 AM
EDIT:This is a LONG post.

LOL You can NEVER ask me too many questions. I learned scripting by jumping in feet first while asking questions when I didn't understand something. I tried to recreate the error and did. I think it's time we take a look at the class Arrow_Enemy. I'm sure you're baffled by this. I'm going to look at Arrow_Enemy because it is what passes off the enemy's information so that the help window can display an enemy's name in battle when you're trying to select which enemy you want to attack. This is what I do when my initial attempts at something fails. I look at the other scripts that do something similar to what I want to do and see what they did to make it work.

This is the line we want to pay attention to in Arrow_Enemy.

  def enemy
    return $game_troop.enemies[@index]
  end
Hrmmm...$game_troop.enemies? It's returning the method enemies in Game_Troop while using the index of the arrow to point to the right enemy but that's not important at this time. What matters is we now have an idea on what method to use but how do we use it? We don't know the contents of $game_troop.enemies so here's what we'll do. We'll output it using a built in RGSS function called p. What does p do? It prints just about anything you could tell it to print! Even class methods like $game_troop.enemies. We'll just change our Window_MonsterName a slight bit and use it to output $game_troop.enemies.

[spoiler=Window_MonsterName]

class Window_MonsterName < Window_Base

  def initialize(troop_id)
    super(0, 0, 100, 100)
    self.contents = Bitmap.new(width - 32, height - 32)
    @troop_id = troop_id
    p $game_troop.enemies[0]
    #refresh
    # The # denotes the start of a comment. Comments are not used by RGSS to run scripts.
    #Comments are useful for leaving behind notes on what something does.
    #A good programmer will note out everything so that even a retarded monkey
    #can understand what the programmer did.
  end
 
  def refresh
    self.contents.clear
    for e in 0...$data_troops[@troop_id].members.size
      self.contents.draw_text(0, 20 * e, 100, 32, $game_troop[@troop_id].enemies[e].name)
    end
  end
end

[/spoiler]
As you can see, I used a comment # to keep RGSS from running the refresh method. Now we can get our output data without the game crashing on us immediately after. Run the above window over yours and lets look at the output.

Errr...what the hell? (http://img167.imageshack.us/img167/9544/enemyoutputue6.png)

Just kidding! It's common to see an output like that. I can tell you what almost everything is. #<Game_Enemy is the class name that the information you're looking at came from. The information you are look at are class METHODS that we can call through $game_troop.enemies. This means we could use $game_troop.enemies[0].enemy_id to return the first enemy's ID number in the database. Catching on to what I have in mind yet? Heh heh...

Now that we know what methods are stored inside $game_troop.enemies, we have a new idea on how to do what we want to do. We can try using the methods to solve our problem.

[spoiler=The solution is here if you want it.]
Here is what I tried with $game_troop.enemies.

class Window_MonsterName < Window_Base

  def initialize(troop_id)
    super(0, 0, 100, 100)
    self.contents = Bitmap.new(width - 32, height - 32)
    @troop_id = troop_id
    #p $game_troop.enemies[0]
    refresh
  end
 
  def refresh
    self.contents.clear
    for e in 0..$data_troops[@troop_id].members.size
      id = $game_troop.enemies[e].id
      self.contents.draw_text(0, 20 * e, 100, 32, $game_enemies[id].name)
    end
  end
end

Now to explain my attempts.


id = $game_troop.enemies[e].enemy_id

I stored the enemy's ID number in the local variable id.

I got this error when I tried running the game in a battle.
undefined method "enemy_id" for <#Game_Enemy:

I'm sure you're a little puzzled now. "We saw it listed in the method output we did! It has to work! Grrr...this makes no sense?!" Am I right? Well, since my initial attempt failed I'm going to look at the Game_Enemy class methods to see if there is a method that'll return the enemy's ID and if there isn't one, then I'm boned.


  def id
    return @enemy_id
  end

Hey~ what's this little beauty? Strange...it's returning @enemy_id? Isn't that the method name I tried to use for the enemy ID in the window? Yes it is. Public variables can also be used in a way similar to class methods when you use  attr_accessor but that's another lesson for another time. Needless to say, @enemy_id doesn't work like that or else I wouldn't have gotten an error. Lets try using $game_troop.enemies[e].id and see if it works.


class Window_MonsterName < Window_Base

  def initialize(troop_id)
    super(0, 0, 100, 100)
    self.contents = Bitmap.new(width - 32, height - 32)
    @troop_id = troop_id
    #p $game_troop.enemies[0]
    refresh
  end
 
  def refresh
    self.contents.clear
    for e in 0..$data_troops[@troop_id].members.size-1
      id = $game_troop.enemies[e].id
      self.contents.draw_text(0, 20 * e, 100, 32, $game_enemies[id].name)
    end
  end
end

There. Now lets try it...error...*mimics a famous comedian* Dont. You. Crash. On. Me. You...BASTARD! Programming takes a LOT of patience. I don't know about the godly scripters like Blizzard, Near Fantastica, and SephirothSpawn but I rarely get things right the first time so yea, programming teaches you a little bit about patience. Anywho, back to our error that we got.


undefined method for nil:NilClass

Okies...something isn't right. Lets output the local variable id and comment our self.contents.draw_text method. Well, the variable outputed the monster's id so we know that's not to blame. I'll try using $data_enemies instead. When a $game_variable fails, the $data_variable usually works.

class Window_MonsterName < Window_Base

  def initialize(troop_id)
    super(0, 0, 100, 100)
    self.contents = Bitmap.new(width - 32, height - 32)
    @troop_id = troop_id
    refresh
  end
 
  def refresh
    self.contents.clear
    for e in 0..$data_troops[@troop_id].members.size-1
      id = $game_troop.enemies[e].id
      self.contents.draw_text(0, 20 * e, 100, 32, $data_enemies[id].name)
    end
  end
end

It worked! YEY! ^-^ Perseverance(sp?) and patience pays off.
[/spoiler]
Title: Re: How can I add windows in my Battle Scene?
Post by: magusbrother on September 16, 2007, 10:12:16 AM
Thank you for the help and the lessons I learned. I will try to improve myself in scripting.
Title: Re: [Resolved]How can I add windows in my Battle Scene?
Post by: Shinami on September 16, 2007, 10:19:32 AM
Always a pleasure. Never a chore. Also, don't try. Just do it.  :blizj:
Title: Re: [Resolved]How can I add windows in my Battle Scene?
Post by: Kokowam on September 16, 2007, 11:14:15 AM
Wow, super good post and it doesn't teach just how to add windows in the Battle Scene. XD :P
Title: Re: [Resolved]How can I add windows in my Battle Scene?
Post by: Shinami on September 16, 2007, 01:13:13 PM
Thank you moo! Rather than just give the answer away, I like to teach new scripters a little about what they want to do and THEN give them their answer.