Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: ForeverZer0 on August 06, 2010, 12:27:55 pm

Title: [XP] Message Choice Window
Post by: ForeverZer0 on August 06, 2010, 12:27:55 pm
Message Choice Window
Authors: ForeverZer0
Version: 1.0
Type: Message Add-on
Key Term: Message Add-on



Introduction

This script will allow you to set up more than the 4 choices that RPGXP limits you to. The window will behave much like the default window and is very easy to use.


Features




Screenshots

None.


Demo

None.


Script


Spoiler: ShowHide

#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Message Choice Window
# Author: ForeverZer0
# Version: 1.0
# Date: 8.5.2010
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#
# Introduction:
#   This script will allow you to set up more than the 4 choices that RPGXP
#   limits you to. The window will behave much like the default window and is  
#   very easy to use.
#
# Features:
#   - Set up as many choices as you need (within reason)
#   - Custom window width, x, and y, or have it center automatically
#   - Can allow/disallow the player from canceling out of window
#   - Uses a single script call
#   - Does not effect the Window_Message class
#
# Instructions:
#   - Configuration is just below.
#   - Use this script call:
#
#       Choices.setup(WIDTH, CHOICES, CANCEL?, X, Y)
#
#   WIDTH   = width of window
#   CHOICES = Array of choices that will be shown. These must be written as a
#             string.   ex.  ['one', 'two', 'three', 'four']
#   CANCEL? = Allowed player to cancel with B button? (true/false)
#   X, Y    = The x and y that the window will be displayed at.
#
#   - Not all of these arguments have to be used. The only two that are required
#     are the WIDTH and CHOICES array. The rest can be omitted.
#   - If the CANCEL? argument is not supplied, it will be true by default.
#   - If the X or Y argument is not supplied, the window will auto-center on
#     the omitted axis.
#
#   - What happens is when a choice is selected, it will set a variable to the
#     that choice's number (first choice is 1, second is 2, etc., etc.)
#   - If the player is allowed to cancel and the B button is pressed, the
#     variable will be set to 0
#   - Now all you must do is create conditional branches below the script call
#     with the condition for each being your variable equal to the respective
#     choice's number.
#
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

#===============================================================================
# ** Choices
#===============================================================================

module Choices
 
 # CONFIGURATION
 #------------------------------------------------------------------------
 
 Variable_ID = 15
 # ID of variable you would like to use for choices.
 Window_Opacity = 160
 # Opacity of choice window (160 is Window_Message default)
 
 #------------------------------------------------------------------------
 # DO NOT CONFIGURE ANYTHING BELOW THIS LINE
 
 def self.setup(width, choices, cancel = true, x = nil, y = nil)
   return unless $scene.is_a?(Scene_Map)
   $game_system.map_interpreter.message_waiting = true
   $game_temp.choice_cancel_type = cancel
   $scene.choice_window = Window_Command.new(width, choices)
   $scene.choice_window.x = x == nil ? (640 - $scene.choice_window.width)/2 : x
   $scene.choice_window.y = y == nil ? (480 - $scene.choice_window.height)/2 : y
   $scene.choice_window.back_opacity = Window_Opacity
 end
end

#===============================================================================
# ** Scene_Map
#===============================================================================

class Scene_Map
 
 attr_accessor :choice_window
 
 alias zer0_choice_window_main main
 def main
   zer0_choice_window_main
   @choice_window.dispose if @choice_window != nil
 end
 
 alias zer0_choice_window_upd update
 def update
   if @choice_window != nil && @choice_window.active
     @choice_window.update
     update_choice_window
   end
   zer0_choice_window_upd
 end
 
 def update_choice_window
   if Input.trigger?(Input::B)
     unless $game_temp.choice_cancel_type
       $game_system.se_play($data_system.buzzer_se)
       return
     end
     $game_system.se_play($data_system.cancel_se)
     $game_variables[Choices::Variable_ID] = 0
     terminate_choice_window
   elsif Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     $game_variables[Choices::Variable_ID] = @choice_window.index + 1
     terminate_choice_window
   end
 end
 
 def terminate_choice_window
   $game_system.map_interpreter.message_waiting = false
   @choice_window.dispose
   @choice_window = nil
 end
end

#===============================================================================
# ** Interpreter
#===============================================================================

class Interpreter
 attr_accessor :message_waiting
end



Instructions

Single script call. (See script)


Compatibility

Should be highly compatible, even with exotic message systems.


Credits and Thanks




Author's Notes

Please report any bugs/issues.
Enjoy!
Title: Re: [XP] Message Choice Window
Post by: stripe103 on August 06, 2010, 03:27:49 pm
Finally, we can get more options without having to have special Custom Message Systems!
Good job. As always. :D
Title: Re: [XP] Message Choice Window
Post by: WhiteRose on August 06, 2010, 04:18:28 pm
Though I'll probably stick to the UMS, this is a great option for those who want to stick with other message scripts yet still want this option. Well done - great work like always.
Title: Re: [XP] Message Choice Window
Post by: ForeverZer0 on August 06, 2010, 04:27:14 pm
Thank you.
I intended for it to be used those who didn't use a custom message system, such as the UMS, but still wanted this feature.

Glad you like.
Title: Re: [XP] Message Choice Window
Post by: G_G on August 06, 2010, 05:43:32 pm
For the cancel thing, add a cancel choice index like RPGXP does.

In the show choices command it says Cance Index or something.
Title: Re: [XP] Message Choice Window
Post by: SBR* on August 07, 2010, 06:50:41 am
Very nice! I haven't tested it, but I'm sure it works perfectly! I can't level you up right now, since I did just level you up for that awesome comment in the Garbage Collection topic, but I'll probably do that later today.

I'd prefer to use a script call in a conditional branch that returns the choice that's chosen by the player over finding the right variable and checking it then. Maybe a good (optional) future?
Title: Re: [XP] Message Choice Window
Post by: legacyblade on August 10, 2010, 03:11:57 pm
I like this script. It'd be useful for making games like Knight of the Old Republic. There are a couple suggestions I have though. First off, it'd be nice to control the height of the window. You'd still be able to have as many options as you want (since window_selectable scrolls if the contents are too big for the window), but it'd look prettier. (you could have 20 options, but only show 4 in the window at a time). You should allow the default values for width, height x, and y to be configurable in the configuration section. That'd make it so we don't have to set X, Y, width, or height unless we want it different than the default. It'd make the script more snazzy.

Again, great script. Just pointing out some ways I think you could make it even better :D
Title: Re: [XP] Message Choice Window
Post by: ForeverZer0 on August 10, 2010, 05:07:52 pm
Quote from: game_guy on August 06, 2010, 05:43:32 pm
For the cancel thing, add a cancel choice index like RPGXP does.

In the show choices command it says Cance Index or something.


@g_g
All you have to do is not set a condition for the option you want to be the "cancel". It will not do anything and have the exact same effect. For example, say you have 2 options (yes and no), only set a condition for "yes" if you want it to be a cancel if the player selects "no". Thats why there is no "Cancel Option".

@legacyblade
I spent more time applying the script template than I took to write the script, so it is lacking in a few areas. Your suggestions sound pretty good. I'll add them in a future version sometime here... :wacko:
Title: Re: [XP] Message Choice Window
Post by: lonely_cubone on August 11, 2010, 11:29:11 am
Quote from: ForeverZer0 on August 10, 2010, 05:07:52 pm
Quote from: game_guy on August 06, 2010, 05:43:32 pm
For the cancel thing, add a cancel choice index like RPGXP does.

In the show choices command it says Cance Index or something.


@g_g
All you have to do is not set a condition for the option you want to be the "cancel". It will not do anything and have the exact same effect. For example, say you have 2 options (yes and no), only set a condition for "yes" if you want it to be a cancel if the player selects "no". Thats why there is no "Cancel Option".


I don't think that's what Game_Guy was getting at. With the event command, you can have a different branch for when you press the Cancel button, which is different from each of the choices. So, with the event command, you could have the choices "Cow", "Sheep", and "Albatross" show up on the screen, but when you press Escape, it acts as a fourth choice that isn't visible to the player. I'm not positive, but I think that's what G_G was referring to.

Anyways, this looks like a great script, and I'm going to use it in the game I'm working on right now.
Title: Re: [XP] Message Choice Window
Post by: Jragyn on August 11, 2010, 12:37:05 pm
I hope this is the proper place to make requests as additions to this idea of script (or this script directly)
You've created now the ability to essentially make a useful number of choices (4 often just doesn't cut it)

Do you have any eventing method that I've overlooked that can enable this to say...
Produce certain choices only if an item is in inventory? If a switch/variable is active?

Simple example:
Spoiler: ShowHide

I want to use this script for making a 'music box' of sorts.
Choices will only appear if say the player has a "CD_Battle Theme" item or "CD_Overworld Theme" item.
Play a song?

Battle Theme      < only appears if the player has CD_Battle Theme item in their inventory
Overworld Theme   < only appears if the player has CD_Overworld Theme item in their inventory
Town Theme        < etc..


If not this script, anyone have any ideas how I could go about this without excessive conditional branching?
Title: Re: [XP] Message Choice Window
Post by: G_G on August 11, 2010, 01:48:30 pm
Could do this. Call this in an event first of all.
$songs = []


Then have a parallel process check if player has an item. If so add the choice to songs. Something like this.
Item in inventory
  $songs.push("Battle Theme")
else
  $songs.delete("Battle Theme")
end


Then just call the window like you would normally except use $songs as the choices.
Title: Re: [XP] Message Choice Window
Post by: statesman88 on January 15, 2011, 02:42:44 am
I was really excited to find this... I spent several hours looking for a script like this. I want to have choices only show up in certain situations, like jragyn00 and game_guy were talking about. So, thanks for making it, and thanks to game_guy for showing the basics of how to use the script that way. :) I have had a lot of fun pushing this script to its limits.

Anyway, three questions/suggestions:
First, this script isn't 100% compatible with the Multiple Message Windows (non-SDK) script (by Wachunga & revised by ForeverZer0). Whenever I use this choice script as the last text window of an event, pressing the action button or Back/Esc/X button not only registers the choice, but it also performs whatever function it would perform if the choice was not present. So, if I exit your choice script menu using Esc, it also brings up the menu, and if I choose a choice with the action button, then I also reactivate the event. Again, this only happens when using both this script and the Multiple Message Windows (MMW), and when the choice is the last text window of the event. Also, the bug does not occur with RMXP's native Show Choices command.

Second, would it be possible to get this choice script window to show up as a speech bubble, like the MMW script's default?

Third, if all of your choice options are conditional on switches or variables, it is possible that your Choices array will be empty, which crashes the game. Currently, I program a check for this into my events. However, it might make this script better to check for an empty array automatically.

Finally, just in case anyone else is interested in how to have choices that only show up under certain conditions, here's how I've done it--there are several complications beyond what game_guy showed above. All of this is event processing/scripting. It's written for somebody who knows as little about scripting as I did a few days ago--all I knew was what variables, switches, and strings are. Now, the only thing I don't know is which variables/objects/arrays to use to discover if an item is in the inventory/equipped or what a character's current stats are.
Spoiler: ShowHide


Quote
$IanSchoolPeople = []
$IanSchoolPeople.clear

if $game_switches[2] == true
then
$IanSchoolPeople.push("Ask About\
Bartholomew")
end


Notes: I created an array, $IanSchoolPeople, which will store my list of choices, and empties it, in case I go through the same conversation more than once. I also check to see if Switch 2 is ON, which means I've met Bartholomew, so I can logically ask about him. Note that it is usually easier to go to Conditional Branch, and type "$game_switches[2] == true" in the script box on page 4 of the Conditional Branch options. I show this method because, using scripting, you can also check the self-switches of other events. :) Just replace $game_switches[switch number] with $game_self_switches[[map number, event number, "switch letter"]], like so:

if $game_self_switches[[2, 8, "B"]] == true

EDIT: Note that, unlike $game_switches, $game_self_switches contains its data in double brackets [[]]. I learned this the hard way--you'll get a "Wrong number of arguments" error if you use single brackets.
You can use a similar process to check for items in the inventory, character stats, etc.  I haven't figured out how to do any of that yet, but all of the information is stored in a number of variables, arrays, and objects. (An array is basically a list of numbers or "strings" of words; an object is a complex combination of variables that are connected to one thing--like one party member's stats, armor, name, and ID number.) Use Conditional Branches or $game_variables[variable number] to check the variables that events usually access.

The command $YourArrayHere.push("New Choice Here") adds a new choice to your list of choices. Next, you need to call up the choice screen:

Quote
Choices.setup(350, $IanSchoolPeople)


The first number--width--is in pixels, I believe. Experiment around 200 to get a feel for it. Now, if you try to run the event, but all of your switches are off, then your array may be completely empty! This will crash the game. So, go right before the Choices.setup script, and enter in a Conditional Branch using    $YourArrayHere.empty? == true   to prevent this crash. You can either set it to "Exit Event Processing" or "Jump to Label" to jump to a different place in your event. Either way, it needs to skip the Choices.setup script. Ideally, it should skip the check-what-the-player-chose scripts ahead, also, or a choice from a previous event might make something weird happen.

Now for the part I had the most fun figuring out--processing what the player chooses. The choice script will set a variable (number 15 by default) to the number of the choice; the first choice in the array is 1, the second is 2, etc. But because the player won't always have the same choices, the number doesn't always mean the same thing. In my game, the player could have the options to "Ask About Prof. Evan" (1), "Ask About Bartholomew" (2), and "Ask About Charlie" (3), but they could also have the options "Ask About Isaac" (1), "Ask About Charlie" (2), and "Ask About Training" (3). The numbers and options don't necessarily match up. So, here's my solution:

Quote
@>Script: $chosen = $game_variables[15] - 1
@>Conditional Branch: Script: $IanSchoolPeople[$chosen] == "Ask About Bartholomew"
   @>Show Text: Bartholomew doesn't seem very interested in
   @>              : his classes, does he?
   @>
:  Branch End
@>Label: JumpHereToSkipChoices
@>

The purpose here is to go backwards and use the choice number to generate the actual Choice the player picked, which we can use as a condition no matter what switches happen to be on or off. Creating a new variable (in this case, $chosen) is necessary because the first choice in $game_variables[15] is 1, but the first choice listed in $IanSchoolPeople[] is string 0, $IanSchoolPeople[0]. If your condition was $IanSchoolPeople[$game_variables[15]], then you would always be one choice off from what you wanted. I don't think I explained that very clearly, but the code works just fine.

Another note: So far as I can tell, the script simply ignores all nil choices. So, even if your array is "Choice A", "Choice B", nil, "Choice D", Choice D will still register as #3, and you will need the technique above to process the choice's consequences.

If any of you more experienced coders see a better way to do the same process, feel free to post. If any of my fellow-newbies have questions, feel free to ask me. Or someone more experienced.
Title: Re: [XP] Message Choice Window
Post by: Jragyn on May 06, 2011, 03:43:08 pm
Holy crap, I was about to ask about exactly what statesman88 answered, and not only did I get an answer, but I got a full lesson on arrays/variables/switches via scripting 0-0

Damn.

Of course, Zer0, if you have a more efficient/alternative method to make this script work like he is talking about, by all means, share. :D
Title: Re: [XP] Message Choice Window
Post by: ForeverZer0 on May 06, 2011, 05:49:34 pm
I suppose I could redo the script real fast. It was originally just something I did for a specific need, then felt with a minor edit or two I could release it. I didn't really put a lot into it at the time, but it won't be hard to improve it.

I may even throw in a couple new features, who knows.  8)
Title: Re: [XP] Message Choice Window
Post by: Jragyn on May 06, 2011, 07:39:10 pm
I like features.
With the main desire being conditional choices  :ninja:

Of course, it seems like most your scripts were developed to accomplish a purpose of your own, haha.
What other scripts have you developed but not released... yet?
Title: Re: [XP] Message Choice Window
Post by: ForeverZer0 on May 06, 2011, 08:06:15 pm
Probably a whole bunch.  I used to write scripts left and right, some useful, some not.  I only released anything that could be compatible with other scripts, or that I thought were worthy.  Many of them, although they are "scripts", are quite worthless unless used for a single specific purpose.  A good example would be the little intro you may see in some of my demos where the letters all come together from off-screen. It may be cool, but what else would you ever use that for?
Title: Re: [XP] Message Choice Window
Post by: Jragyn on May 07, 2011, 11:28:12 am
inbattlecutscenes, advertisements(story-game-related), puzzles (see half the letters and guess what it says? idk, creativity beckons that) or... well, I dunno.

I just like messing with scripts and their functionality parts(usually below the "don't edit past here" line) and seeing what I can do with it. :D And though I understand what the scripts do, and what each segment does, its a whole other story trying to put one together on my own. >.<
Title: Re: [XP] Message Choice Window
Post by: Rolandojis on October 13, 2011, 11:05:05 pm
My script call was like this:
(http://i810.photobucket.com/albums/zz25/monowix/scriptshow.png)
I dont really know if its correct or what do I have to change but when I get to the part of the game where it should appear it shows this:
(http://i810.photobucket.com/albums/zz25/monowix/error.png)

Please help  :'(
Title: Re: [XP] Message Choice Window
Post by: ForeverZer0 on October 13, 2011, 11:48:01 pm
The choices are not in an array.
Simply add a [ before the first choice and a ] after the last choice (before the comma).
Title: Re: [XP] Message Choice Window
Post by: Eriah on March 23, 2012, 05:43:22 pm
I know this script is old by now, but I wanted to point something out, since I'm currently using it in my game.

I made a demo event that triggers with the action button. When selecting a choice, it's supposed to start a track, and then the event ends automatically. I select the choice, the track plays, and the event ends like it should. But when selecting the choice, since the action button was pressed to select it, the event triggers again. Thus meaning the action button reads on the map even after the choice window is closed. I'm not sure if that's only my game doing it or not, but it may become a bit of an inconvenience for some others.

What I'm doing is setting it to go to another event page with an action button trigger after selecting the choice, which makes it go back to the original page. Thus the trigger doesn't restart the event. So it's not much of a problem to me, personally, since I can get around it.

I'm thinking the reason no one pointed this out before is because they had commands go on after the choice is selected, which would negate the press of the action button, and so nothing happens to them. But for events that close right after the selection, it'll be an issue.
Title: Re: [XP] Message Choice Window
Post by: ForeverZer0 on March 23, 2012, 05:48:20 pm
I don't script anymore, nor really even update my old scripts, but you can solve it with a script call. After the script call for the choices, just add an extra line: "Input.update".
Title: Re: [XP] Message Choice Window
Post by: Zangetsu on June 28, 2014, 02:26:32 am
Sorry for necroposting...

But if anyone can help me out there, I get a syntax error when trying to add a choice with an apostrophe in, as if I want to write "I don't know" as one of the choices, the script won't let me. I get that it's a scripting thing, but is there any way to override this without making my choices seem awkwardly phrased?

Many thanks to anyone who can help.
Title: Re: [XP] Message Choice Window
Post by: ArcaneAlchemy on June 28, 2014, 03:09:21 am
Quote from: Zangetsu on June 28, 2014, 02:26:32 am
Sorry for necroposting...

But if anyone can help me out there, I get a syntax error when trying to add a choice with an apostrophe in, as if I want to write "I don't know" as one of the choices, the script won't let me. I get that it's a scripting thing, but is there any way to override this without making my choices seem awkwardly phrased?

Many thanks to anyone who can help.


Well, the apostrophe is usually used to declare strings in most programming languages. What's happening is that the program is thinking that you're trying to end the string literal at the second apostrophe. If they don't match, you'll get that syntax error as well. Now I don't know if this is gonna help but try this.

puts "I don\'t know"

the forward slash is used to ignore the apostrophe it is followed by and continue with the string. http://en.wikibooks.org/wiki/Ruby_Programming/Strings
Title: Re: [XP] Message Choice Window
Post by: G_G on June 28, 2014, 03:28:40 am
This would be pointless.

puts "I don\'t know"

Since you start and end the string with double quotes, you don't have to escape single quotes and vica versa.

'I don\'t know'

Or

"Welcome to my...\"home\"...if you can call it that!"

You can have "It's fine!" And 'It felt "weird" seeing him again'

Chances are you're putting 'I don't know'. To fix it, simply do 'I don\'t know' or "I don't know". Either way should work.
Title: Re: [XP] Message Choice Window
Post by: ArcaneAlchemy on June 28, 2014, 04:12:31 am
Oh lol, just tried double quotes. You're right. Wow, I don't know why I thought that.  :facepalm:
Title: Re: [XP] Message Choice Window
Post by: Zangetsu on July 06, 2014, 06:59:31 pm
Thanks so much, guys :D This helps a whole bunch.

Once more question, is there any way to centre the text IN the choices? Not centre the message window itself, but the choice's text. Thanks!
Title: Re: [XP] Message Choice Window
Post by: Zangetsu on November 16, 2014, 02:29:04 am
Sorry for necroposting once more... I've been using this script a lot lately, therefore I've had some time to explore and find some weird spots in my games concerning it. And being useless in coding, I wouldn't be able to fix this problem on my own no matter what I do. That's why I'm posting here.

Here's the thing: When I show a picture and call the script, the choices don't show up. At first I thought I didn't draw up the choices, but when I used the up and down arrow keys, I could hear the sound of the cursor moving from choice to choice. So it's there--it's just that the picture (which, by the way, is the size of the game window) and completely obscures it. I guess overlay is the word?

How can I fix it and get the choices to come out on top?

Thanks in advance to anyone who can help!