[XP] Message Choice Window

Started by ForeverZer0, August 06, 2010, 12:27:55 pm

Previous topic - Next topic

ForeverZer0

August 06, 2010, 12:27:55 pm Last Edit: August 06, 2010, 02:17:36 pm by Blizzard
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


  • Set up as many choices as you need (within reason)
  • Custom width, x, and y, or use the auto-center feature
  • Uses a single script call
  • Does not effect the Window_Message class.



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


  • ForeverZer0



Author's Notes

Please report any bugs/issues.
Enjoy!
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

stripe103

Finally, we can get more options without having to have special Custom Message Systems!
Good job. As always. :D

WhiteRose

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.

ForeverZer0

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.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

G_G

For the cancel thing, add a cancel choice index like RPGXP does.

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

SBR*

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?

legacyblade

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

ForeverZer0

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:
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

lonely_cubone

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.

Jragyn

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?
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

G_G

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.

statesman88

January 15, 2011, 02:42:44 am #11 Last Edit: January 16, 2011, 12:39:17 pm by statesman88
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.

Jragyn

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
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

ForeverZer0

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)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Jragyn

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?
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

ForeverZer0

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?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Jragyn

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. >.<
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Rolandojis

My script call was like this:

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:


Please help  :'(

ForeverZer0

The choices are not in an array.
Simply add a [ before the first choice and a ] after the last choice (before the comma).
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Eriah

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.