Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: ForeverZer0 on July 14, 2010, 05:34:41 pm

Title: [XP] Script-Command Messages
Post by: ForeverZer0 on July 14, 2010, 05:34:41 pm
Script-Command Messages
Authors: ForeverZer0
Version: 1.0
Type: Message Add-on
Key Term: Message Add-on



Introduction

Very simple fix to a (personally) irritating problem with the normal text command for events.  I prefer to use slightly smaller font sizes for my games, but with the default event command system, I am forced to break to a new line at intervals, even though the text does not even extend to the end of the message box. This script will fix that issue by using the "Script"command to write your text in, and automatically size the lines correctly and go to the next line only when required, and even to a second box if the total text does not fit in a single message box.


Features




Screenshots

None.


Demo

None.


Script

Here's the script.
Spoiler: ShowHide

#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# Script-Command Messages
# Author: ForeverZer0
# Version: 1.0
# Date: 7.14.2010
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
#
# Introduction:
#   Very simple fix to a (personally) irritating problem with the normal text
#   command for events.  I prefer to use slightly smaller font sizes for my
#   games, but with the default event command system, I am forced to break to a
#   new line at intervals, even though the text does not even extend to the end
#   of the message box. This script will fix that issue by using the "Script"
#   command to write your text in, and automatically size the lines correctly
#   and go to the next line only when required, and even to a second box if the
#   total text does not fit in a single message box.
#
# Features:
#   - Very simple to use, merely uses the "Script" command instead of the "Show
#     Text" command.
#   - Automatically breaks to new lines, but only when needed.
#   - Automatically breaks to a new message box if total text does not fit in
#     one.
#   - Can fit much more text into message boxes.
#   - Very high compatibility with all(?) message systems out there. It creates
#     the proper "Show Text" commands on the fly, so it does not alter any
#     scripts, just reorganizes how the event command is interpreted.
#
#  Instructions:
#   - Use this script call:  text("MESSAGE", TEXT_WIDTH)
#   - MESSAGE = The message you want displayed. Must be a string. ("")
#   - TEXT_WIDTH = can be omitted, and the default value will be used. The text
#                  will break to a new line after it reaches the given width.
#
# Credits/Thanks:
#   - Special thanks to Blizzard. It uses his text_slice method to measure
#     the line lengths.
#
# Notes/Issues:
#   - Do not use this command with messages that are very short.
#   - Commands such as "\v[ID]", \c[COLOR], etc. must have an extra "\" added to
#     work properly, and a backslash character must be written as "\\\". It is
#     a minor nuisance, but easiest way to bypass the problem.
#
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

  DEFAULT_TEXT_WIDTH = 448
  # This is good for the default message system's message boxes. If you use a
  # different size message box, set this to the bitmap's width.

class Interpreter
 
  def text(string, width = DEFAULT_TEXT_WIDTH)
    if $game_map.command_added[@event_id] == nil
      $game_map.command_added[@event_id] = []
    end
    return if $game_map.command_added[@event_id].include?(@index)
    bitmap, words = Bitmap.new(width, 32), string.split(' ') 
    result, current_text, command = [], words.shift, []
    words.each_index {|i|
      if bitmap.text_size("#{current_text} #{words[i]}").width > width
        result.push(current_text)
        current_text = words[i]
      else
        current_text = "#{current_text} #{words[i]}"
      end
      result.push(current_text) if i == words.size-1}
    bitmap.dispose
    result.each_index {|i|
      code = i%4 == 0 ? 101 : 401
      command.push(RPG::EventCommand.new(code, @event_id, [result[i]]))}
    command.each_index {|i| @list.insert(@index+1+i, command[i])}
    $game_map.command_added[@event_id].push(@index)
  end
end 

class Game_Map
 
  attr_accessor :command_added
 
  alias zer0_script_message_setup setup
  def setup(map_id)
    @command_added = []
    zer0_script_message_setup(map_id)
  end
end



Instructions

Uses a single, simple script command (see script).


Compatibility

Should be compatible with everything, including exotic message systems.


Credits and Thanks




Author's Notes

Enjoy!
Title: Re: [XP] Script-Command Messages
Post by: WhiteRose on July 16, 2010, 11:50:08 pm
<3

You have just corrected one of the last major problems with RMXP.
Title: Re: [XP] Script-Command Messages
Post by: ForeverZer0 on July 18, 2010, 05:55:04 pm
Quote from: WhiteRose on July 16, 2010, 11:50:08 pm
<3

You have just corrected one of the last major problems with RMXP.


8)
Just trying to fix a stupid simple problem in a simple way. Though I know many could care less about this.
Title: Re: [XP] Script-Command Messages
Post by: WhiteRose on July 18, 2010, 07:40:41 pm
I do have one question. Will messages typed using this script be compatible with scripts (particularly the UMS) that use in-message codes? For example, when I write dialog in games in which the UMS is used, I will add pauses between sentences by typing \p[30] to make it sound more natural, like someone is actually speaking.
Title: Re: [XP] Script-Command Messages
Post by: ForeverZer0 on July 18, 2010, 08:38:58 pm
Quote from: WhiteRose on July 18, 2010, 07:40:41 pm
I do have one question. Will messages typed using this script be compatible with scripts (particularly the UMS) that use in-message codes? For example, when I write dialog in games in which the UMS is used, I will add pauses between sentences by typing \p[30] to make it sound more natural, like someone is actually speaking.


I didn't test it with UMS, but it should still work the same. It still runs the code through the normal Window_Message class. I know that in other message systems (not sure about the UMS) the refresh method of this is what searches for patterns to replace. You will still have to use the double backslashes, which is a minor bug I haven't worked out yet.
Title: Re: [XP] Script-Command Messages
Post by: lonely_cubone on July 19, 2010, 12:43:59 pm
Quote from: ForeverZero on July 18, 2010, 05:55:04 pm
8)
Just trying to fix a stupid simple problem in a simple way. Though I know many couldn't care less about this.


Sorry, it really bugs me when people say that wrong. :P

Anyways, this script is amazing! The only problem is, I have to go through all my games now and change all the text, but it's worth it. Level up!
Title: Re: [XP] Script-Command Messages
Post by: poxy on July 19, 2010, 05:02:13 pm
This is pretty handy. Nice to put down longer messages in one go if you are using message codes like in UMS. Though RMXP still tries to sneak in return cases where they're not wanted in the script command -.- ...
Title: Re: [XP] Script-Command Messages
Post by: Sacred Nym on July 20, 2010, 03:47:52 am
I'm trying not to be rude about this, but this is the single most useless script I have ever seen. It's basically a glorified batch-text entry command (which does exist in RMXP for those who aren't aware) that can't seem to handle line breaks properly. Don't believe me?

Here's what I did with Batch Text Entry:
Spoiler: ShowHide
(http://img838.imageshack.us/img838/9839/batchtextex.png)


Same thing, done with the Script:
Spoiler: ShowHide
(http://img832.imageshack.us/img832/8640/scripttextex.png)


The Script call of the above, for reference
Spoiler: ShowHide
text("Script:
AAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA")


As a result of this, the user is required to relinquish formatting control to the computer, which is BAD. I want my text boxes done my way.

Also the script removes instances of multiple spaces in a row, and fails to run on strings that start with a space. Yay for removing options! :V:

On top of this, the script fails to function in battle. If it's in the actual game, the script simply does nothing. If it's in Battle test mode however, you get this error.
Spoiler: ShowHide
QuoteScript 'Text' line 54: NoMethodError occured.
undefined method ` []'for nil:NilClass


And ANOTHER thing. The feature of automatically splitting text up into each window, the main reason why Batch text entry exists in RMXP, is severely weakened by the small size of the Call Script box. And no, it doesn't scroll.

Finally, this script brings absolutely nothing new that RMXP can't do already. This is less than a glorified Batch entry window with formatting options thrown out the window. I simply don't understand why everyone is jumping for joy over this.  :uhm:
Title: Re: [XP] Script-Command Messages
Post by: SBR* on July 20, 2010, 08:55:02 am
Use
"LINE1\nLINE2"
to split lines. I can't remember if the 'n' should be capital or not.

But I'm still wondering: why can't your rewrite the Message script, so that it can also be done with the event command?
Title: Re: [XP] Script-Command Messages
Post by: lonely_cubone on July 20, 2010, 09:18:33 am
Quote from: SBR* on July 20, 2010, 08:55:02 am
But I'm still wondering: why can't your rewrite the Message script, so that it can also be done with the event command?

The whole point is to get rid of the width restrictions imposed by the size of the box in the event command. That's why it uses the script command instead.

Quote from: SBR* on July 20, 2010, 08:55:02 am
Use
"LINE1\nLINE2"
to split lines. I can't remember if the 'n' should be capital or not.

Again, this defeats the purpose, because the text is supposed to be made to fit into the box automatically. That's the point of the script.
Title: Re: [XP] Script-Command Messages
Post by: SBR* on July 20, 2010, 12:31:50 pm
@Cube: 1) Aha!
2) I was answering Sacred's question.
Title: Re: [XP] Script-Command Messages
Post by: Sacred Nym on July 20, 2010, 01:15:04 pm
Quote from: SBR* on July 20, 2010, 08:55:02 am
Use
"LINE1\nLINE2"
to split lines. I can't remember if the 'n' should be capital or not.

The script reads \n as a space. Even if it did work, that sort of thing should be in the instructions, so it would change my criticism instead of removing it.

Quote from: lonely_cubone on July 20, 2010, 09:18:33 am
The whole point is to get rid of the width restrictions imposed by the size of the box in the event command. That's why it uses the script command instead.

This is why you use Batch text entry. I agree that the 3 line box is a flaw in RMXP (which didn't exist in fanlations, if memory serves). But there's Batch text entry which gives you 22 lines of text that will automactically be split into individual show text commands. All without fucking your formatting.Sure it's not completely easy to edit later, but this is a non-issue if you actually prep and proofread in the text editor of your choice.

Quote from: lonely_cubone on July 20, 2010, 09:18:33 am
Again, this defeats the purpose, because the text is supposed to be made to fit into the box automatically. That's the point of the script.

Did you even read my post? :uhm: Taking away options in order to do something that RMXP is already capable of (without revoking aforementioned options or introducing other flaws) is a waste.
Title: Re: [XP] Script-Command Messages
Post by: WhiteRose on July 20, 2010, 01:51:51 pm
Don't worry; F0 knows what he's doing. Like everyone else around here, he's trying to help people use the RMXP engine to its fullest potential. Take a look at his other scripts -- does that look like something an amateur who doesn't know how to properly use the Batch Entry command would produce? Of course not. Having spent many hours frustrated with the default text entry system and the way it cuts off text for no apparent reason, I'm very appreciative of F0 and his decision to create and release this script. If you don't like it, no one is forcing you to use it.
Title: Re: [XP] Script-Command Messages
Post by: SBR* on July 20, 2010, 03:39:56 pm
Quote from: Sacred Nym on July 20, 2010, 01:15:04 pm
Quote from: SBR* on July 20, 2010, 08:55:02 am
Use
"LINE1\nLINE2"
to split lines. I can't remember if the 'n' should be capital or not.

The script reads \n as a space. Even if it did work, that sort of thing should be in the instructions, so it would change my criticism instead of removing it.

Quote from: lonely_cubone on July 20, 2010, 09:18:33 am
The whole point is to get rid of the width restrictions imposed by the size of the box in the event command. That's why it uses the script command instead.

This is why you use Batch text entry. I agree that the 3 line box is a flaw in RMXP (which didn't exist in fanlations, if memory serves). But there's Batch text entry which gives you 22 lines of text that will automactically be split into individual show text commands. All without fucking your formatting.Sure it's not completely easy to edit later, but this is a non-issue if you actually prep and proofread in the text editor of your choice.

Quote from: lonely_cubone on July 20, 2010, 09:18:33 am
Again, this defeats the purpose, because the text is supposed to be made to fit into the box automatically. That's the point of the script.

Did you even read my post? :uhm: Taking away options in order to do something that RMXP is already capable of (without revoking aforementioned options or introducing other flaws) is a waste.


I thought
\s
was a space?
Title: Re: [XP] Script-Command Messages
Post by: poxy on July 20, 2010, 07:08:33 pm
The batch text entry is new to me... I just read up on it. But it's still flawed, as it has the same width as the show text command.

Scenario: me typing a message using CCoa's UMS, adding /p[10] after commas, the /p[10]s manage to push the last word down one line, where the word would print normally without the /p[10]s. Same story using batch text entry and this script (unfortunately :()

Idea: a script similar to this one that discounts return cases and only allows line break using a visible command such as /n. Though I don't know if that's more likely to cause incompatibility... well, it's just a suggestion.
Title: Re: [XP] Script-Command Messages
Post by: Sacred Nym on July 20, 2010, 10:46:50 pm
Quote from: SBR* on July 20, 2010, 03:39:56 pm
I thought
\s
was a space?

That's not at all what I was trying to say. That example you gave me, just try it yourself with this script.

Quote from: poxysmash on July 20, 2010, 07:08:33 pm
The batch text entry is new to me... I just read up on it. But it's still flawed, as it has the same width as the show text command.

Scenario: me typing a message using CCoa's UMS, adding /p[10] after commas, the /p[10]s manage to push the last word down one line, where the word would print normally without the /p[10]s. Same story using batch text entry and this script (unfortunately :()

Idea: a script similar to this one that discounts return cases and only allows line break using a visible command such as /n. Though I don't know if that's more likely to cause incompatibility... well, it's just a suggestion.


Hm, I do see what you mean there. I typically don't use \p for that particular reason. I'm more likely to let soft pauses like commas slide and break to a new window when there's a hard pause (ie. long enough to take a breath). Fit Window to Text helps a lot too. :D

Regarding your idea, and I'm only assuming this is possible, perhaps rather than full manual on line breaks, instead a system where you concatenate one line of text to the next. As an example,
Man:
"1 2 3\+
4 5 6"


Would return:
QuoteMan:
"1 2 3 4 5 6"


Much less annoying and less space wasting in the box than \n on every line.
Title: Re: [XP] Script-Command Messages
Post by: ForeverZer0 on July 21, 2010, 06:04:57 pm
@sacred nym
Sorry, I did not mean for this script to offend you on such a personal level. I promise you it was not intentional, and I want you to know just how sorry I am for even thinking of writing this, and I beg for your full forgiveness so that I can sleep tonight.

@whiterose
Amen. Thank you, but I'm afraid sacred nym is just so upset from my obvious personal attack of writing the script, and absolute and total ignorance of RMXP to understand what you meant.
Title: Re: [XP] Script-Command Messages
Post by: Sacred Nym on July 22, 2010, 01:06:04 am
Quote from: ForeverZero on July 21, 2010, 06:04:57 pm
@sacred nym
Sorry, I did not mean for this script to offend you on such a personal level. I promise you it was not intentional, and I want you to know just how sorry I am for even thinking of writing this, and I beg for your full forgiveness so that I can sleep tonight.

@whiterose
Amen. Thank you, but I'm afraid sacred nym is just so upset from my obvious personal attack of writing the script, and absolute and total ignorance of RMXP to understand what you meant.

Hold up right there. I'm not offended at all. Though maybe I should be offended that you think I'm offended. :V: Nah, I was just in a ranty mood when I posted earlier (also it was 2 in the morning).

To add to my earlier statements. Is this script hellishly flawed? Yes. Can it be fixed? Yes. Some if not all of the flaws can be fixed and/or worked around. Like the bit about the tiny Call Script box. Worked around by storing strings in a module or something then calling that. Doesn't even really need effort on your part, just a suggestion amongst the instructions or even the framework already set up.

Again, I'm sorry if I sounded ranty, just felt I needed to point out the flaws so you could try to fix them.

I also mucked with the script a bit to try and add forced Line Breaks with a code. I have something that seems to work though not perfectly, and it seems a bit clunky. If you like I can PM you the edit, perhaps something to work from, maybe. (I have no confidence in my scripting abilities >.>)
Title: Re: [XP] Script-Command Messages
Post by: ForeverZer0 on July 23, 2010, 04:43:49 pm
As for a module storing long strings, that kind of defeats the purpose of a quick on the fyly edit. I was just bored and decided to mess around with the message system. I write a lot of stuff, some of it better than others. I post a lot of it and see if anybody can make use it.
Title: Re: [XP] Script-Command Messages
Post by: lonely_cubone on August 12, 2010, 05:16:53 pm
Is there any reason this isn't in the database? I've been using it, and it's a really helpful little script :D