Jump to content
Sign in to follow this  
TaranAlvein

Having trouble scripting Show Choices

Recommended Posts

I know, normally I'd just use the default editor script, but I needed to make something that allows you to choose a party member to take an action.  I can populate the choice list itself no problem, but I can't get it to recognize which choice has been made.  An example of the code, if there were three party members...

 

params = []
choices = []
choices.push($game_party.members[0].name)
choices.push($game_party.members[1].name)
choices.push($game_party.members[2].name)
params.push(choices)
params.push(0)
setup_choices(params)

case params
when 1
$game_variables[15] = $game_party.members[0].name
when 2
$game_variables[15] = $game_party.members[1].name
when 3
$game_variables[15] = $game_party.members[2].name
end

 
Clearly, I'm not using the Case statement correctly, but I'm having trouble figuring out what I'm missing.  Any help would be greatly appreciated!
Edited by TaranAlvein

Share this post


Link to post
Share on other sites

Try

case $game_message.choice_proc

 

instead

Share this post


Link to post
Share on other sites

That didn't work either, I'm afraid.  Thanks anyway, though.

 

EDIT:  Also, I tried pasting it to a new project, since sometimes things just don't work for some reason, but it still didn't work there, either.

Edited by TaranAlvein

Share this post


Link to post
Share on other sites

There are so many problems with this, I don't even know where to start.

 

The reason the case statement itself is not working is because you're trying to work it on an array. The value of the array is going to look something like this when you print it out in console:

[["Eric", "Natalie", "Terence"], 0]

Or whatever the names of the first three party members happen to be. It's never going to be "1" or "2" or "3" like you're checking for in your case statement. Same deal with running it on "$game_message.choice_proc", which is an object and not an integer.

 

What it looks like you want to run your case statement on is the index of the choice selected by the player. But that choice index hasn't been saved in any variable and you haven't written any code for remembering it either.

 

Not even the Game_Interpreter bothers remembering the choice. It just directly moves onto the proper branch of event code/commands as it reads the index of the selected choice (which it takes from the cursor index of Window_ChoiceList and, apart also not being stored is indexed from 0, not 1). That's what you see in the line of code that goes "$game_message.choice_proc = Proc.new {|n| @branch[@indent] = n }" in that setup_choices() method.

 

Of course, with your code, you have the little problem of... not actually having any event code for it to move onto when it tries that. So it ends up doing nothing.
 

And then you might think "OK, I'll use a variable that stores the choice" and do something like this:

 

 

 

$game_message.choice_proc = Proc.new {|n| choice_index = n}

case choice_index
 when 0
  $game_variables[15] = $game_party.members[0].name
 when 1
  $game_variables[15] = $game_party.members[1].name
 when 2
  $game_variables[15] = $game_party.members[2].name
end

 

 

 

...But then you'll run into the OTHER reason why your code wouldn't work anyway. And that's because the Game_Interpreter keeps on running even if you haven't selected a choice yet. Your case statement is going to process BEFORE the player has selected a choice.

 

There's only two solutions I can think of off the top of my head. The first is something like this:

 

 

 

$game_message.choice_proc = Proc.new {|n| $game_variables[15] = params[0][n] }

# Or you can chuck your whole case statement in the proc as well. The idea is that you're
# overwriting the proc so that it sets your variable to the choice, instead of trying to
# look for event code that doesn't exist, as it does by default.

 

 

 

Or my preferred solution:

 

 

 

Use the Show Choices event command.

Seriously.
Why the flipping heck would you ever want to do this by script in the first place?

...Yeah. Scripting is not a cure-all panacea to every single problem, my friend.

 

 

 

Share this post


Link to post
Share on other sites
Or my preferred solution:

 

 

Use the Show Choices event command.

Seriously.
Why the flipping heck would you ever want to do this by script in the first place?

...Yeah. Scripting is not a cure-all panacea to every single problem, my friend.

 

 

 

 

While I appreciate your helping me out with this, don't be a judgmental ass.  I use the default editor as much as I can, but when I have to script something, I have to script something.  There are plenty of valid uses for a longer Show Choice list.  Suppose I had any kind of choice at all with more than four options, and thought it was more aesthetically pleasing to have them on one list instead of a series of nested lists?  Hell, what if it was more than just looks?  What if the player had to make an important choice that happened to have more than four options, and I wanted them to see all their choices at once, so they could weigh them equally?

 

One-liners may make you think you're cool, but they aren't constructive at all.  Next time, I'd rather you didn't help me at all than point out what I'm doing wrong with a snide remark.

Edited by TaranAlvein

Share this post


Link to post
Share on other sites

If I wanted to be a "judgmental ass", I would've begun with something like this: "You clearly don't know what you're doing, so please don't pretend you do by saying stuff like 'clearly I'm not using my case statement correctly' when I can spot two other bigger things wrong that do not involve your case statement".

 

That would be me making a judgmental assumption about your person. I could've. Instead, I opted just to criticize your code. And that solution which you took as a "snide remark" is, in fact, something you should genuinely be thinking about when trying to script something. Since you seem to have missed my point, I will explain in more detail.

 

There are plenty of valid uses for a longer Show Choice list.

 

Here's the thing: there are plenty of valid uses for a longer CHOICE list, that much is true.

 

But the in-built "Show Choices"? That's another story.

 

Just looking at it logic-wise, you can see the particular code for "Show Choices" goes hand-in-hand with events commands. There is nothing in the default code for "Show Choices" that handles the outcome of a choice; it is all redirected back to the originating event. That itself should give you a hint that you are better off looking for another way to handle it. But okay, let's say I was stubborn and tried it anyway, and stored the outcome in a variable to process with conditional branches or whatever because I thought it made my event code look neater or because I wanted an easy way to show >4 choices on the screen.

 

Oh wait. What the **** is this. My message box isn't staying up when my scripted choices open like when I use the event command. What's more, my events that were supposed to move AFTER selecting my choice have started moving at the same time or even before my Show Choices box was opening. Oh, and what's this, once I have more than 11 choices on my list, the box starts horribly stretching out of the screen instead of scrolling like my item menu. Why is this happening.

 

Maybe you've already run into those problems by now. Or maybe you haven't, and then you'll go around asking for help, except not from me because you think I'm a "judgmental ass" and not constructive enough.

 

Or maybe this time you'll heed the suggestion that trying to make an extended choices window by using "Show Choices" in a script call is seriously a messier idea than nested choices. In my opinion, even making a custom choices window is a better idea - it would need about as much effort as re-fitting the existing "Show Choices" code to work properly in a script call and you would at least know everything that goes on with your custom window.

 

I could make a comment on what I judge the likelihood of you doing those things is, but I won't. I will, however, accede to your request not to help the next time you come around seeing as I don't possess any particular masochistic tendencies. Do have a nice day.

Share this post


Link to post
Share on other sites

Not judgmental or snide?  Let's see...

 

There are so many problems with this, I don't even know where to start.

 

...

 

Use the Show Choices event command.

Seriously.
Why the flipping heck would you ever want to do this by script in the first place?

Yeah. Scripting is not a cure-all panacea to every single problem, my friend.

 

 

I rest my case.

 

The question is answered and the thread can be closed.

Edited by TaranAlvein

Share this post


Link to post
Share on other sites

 

Not judgmental or snide?  Let's see...

 

 

<The facts>

 

I rest my case.

 

Oh, the irony. And this time, my snideness IS intentional, Mr. Pot.

 

Does make me a little sad that I typed out my previous response for nothing, but my fault for feeding the troll I suppose.

Share this post


Link to post
Share on other sites

Okay, enough of this.

9RWO0dm.png This thread is closed, due to being solved. If for some reason anybody would like to re-open this thread, just send me a PM or report the thread. (=

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted