dialog/special encounter problem

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: dialog/special encounter problem
Warrior
Member # 5861
Profile Homepage #0
Ok, this is my first time trying to create a BOA scenario. I don't have a story yet, but I'm just trying to get myself familiar with scripting and all that jazz until I do decide what I want to make a scenario about.

Ok, the current problem I'm having is with a special encounter. I have a town and I have a beggar in this town. Here's the code:

beginstate11;
reset_dialog();
add_dialog_str(0, "You see a beggar holding out a tin cup to you. _Could you please spare a few coins so I can eat?_" 0);
add_dialog_choice(0, "Yes I will. (Give him coins)");
add_dialog_choice(1, "Sorry, I don't have any myself.");
add_dialog_choice(2, "Back off old man and leave me alone!");
if (run_dialog(0) == TRUE) {
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
}
else {
message_dialog("He sighs and sulks away."," ");
}
else {
message_dialog("He spits in your face and walks away, muttering about how young people only think of themselves these days."," ");
}
break;
Ok, the problem I'm having is that when I play the scenario and I choose the third option, it gives the response "He sighs.." instead of "He spits...". I've tried figuring out what I should do differentely, and I've tried all of my resources (docs, westra's cookbook, Kelandon's page, plus looking at other scenarios). Any ideas??

[ Saturday, November 26, 2005 19:01: Message edited by: iluvhorses ]
Posts: 72 | Registered: Sunday, May 29 2005 07:00
Shock Trooper
Member # 932
Profile #1
Have you tried looking at door.txt script that comes with every scenario? It has an example of how to do this sort of thing.

The problem you are having is that there is only supposed to be one ELSE statement at the end of an IF-ELSE statement. This is because the ELSE statement is the "in the advent of nothing matching the preceeding if statements, do this".

But... you can have something similar to this:

if (condition) {
action;
}
else if (condition) {
action;
}
else {
action;
}


--------------------
Microsoft Patents Ones, Zeroes (March 25, 1998)
"Asians are good at Starcraft because they're always squinting, thus they can see things sharply. Remember to always squint in war." ~ Sun-Tzu
Posts: 215 | Registered: Sunday, April 7 2002 08:00
...b10010b...
Member # 869
Profile Homepage #2
What CPeters said, since he got in before me.

Note, however, that you should only call run_dialog once per encounter and save its value to a variable, so the player doesn't have to deal with the dialog box twice. That's the purpose of lines like "choice = run_dialog(0)" that you see in scripts.

So here's the fixed version of your script:

(Note that this requires that "choice" be defined as a variable in the variables list at the start of the script)

beginstate 11;
reset_dialog();
add_dialog_str(0, "You see a beggar holding out a tin cup to you. _Could you please spare a few coins so I can eat?_" 0);
add_dialog_choice(0, "Yes I will. (Give him coins)");
add_dialog_choice(1, "Sorry, I don't have any myself.");
add_dialog_choice(2, "Back off old man and leave me alone!");
choice = run_dialog(0);
if (choice == 1) {
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
end();
}
if (choice == 2) {
message_dialog("He sighs and sulks away."," ");
end();
}
message_dialog("He spits in your face and walks away, muttering about how young people only think of themselves these days."," ");

break;
By the way, you should also make sure that you find some way to handle the situation where the player offers to give money (selects the first option) but doesn't actually have any gold.

[ Saturday, November 26, 2005 16:17: Message edited by: Thuryl ]

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Warrior
Member # 5861
Profile Homepage #3
Ok, that helped a little - 1 slight problem. I got it to give me the correct response when I choose option three, however the
choice = run_dialog(0); is not working. I keep getting an error message saying "Unknown command choice in line 39" (or whatever line it happens to be in). I tried declaring it in the variables sectiong, and where Thuryl put it in the code, but it still doesn't work. And without it the dialog box repeats when I choose the 2nd and 3rd options.

BTW, about what Thuryl suggested about having a way to handle it if the player offers the money but has none - would I use another if statement for that???

(bear with me, guys, I'm new to this, you'll probably hear more from me on this forum than the other one!)
Posts: 72 | Registered: Sunday, May 29 2005 07:00
...b10010b...
Member # 869
Profile Homepage #4
Post your entire town script so that we can see if you've declared the variable correctly.

And yes, you'd use another if statement to check if the party has any gold. You can nest if statements inside each other. Just make sure you keep track of all the braces.

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Warrior
Member # 5861
Profile Homepage #5
// TOWN SCRIPT
// Town 2: New Town

// This is the special encounter script for this town.

begintownscript;

variables;

choice = run_dialog(0);

body;

beginstate INIT_STATE;
// This state is called whenever this town is entered.
enable_add_char(0);
set_crime_tolerance(2);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
message_dialog("You walk out of New Town, curious as to what adventures you can find!"," ");
break;

begingstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate11;
reset_dialog();
add_dialog_str(0, "You see a beggar holding out a tin cup to you. _Could you please spare a few coins so I can eat?_" 0);
add_dialog_choice(0, "Yes I will. (Give him coins)");
add_dialog_choice(1, "Sorry, I don't have any myself.");
add_dialog_choice(2, "Back off old man and leave me alone!");
choice = run_dialog(0);
if (choice == 1) {
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
}
else if (choice == 2) {
message_dialog("He sighs and sulks away."," ");
}
else {
message_dialog("He spits in your face and walks away, muttering about how young people only think of themselves these days."," ");
}
break;
Anything??

[ Saturday, November 26, 2005 18:59: Message edited by: iluvhorses ]
Posts: 72 | Registered: Sunday, May 29 2005 07:00
Off With Their Heads
Member # 4045
Profile Homepage #6
Declaring the variable looks like this:
int choice; Thus your script ought to look like this:
// TOWN SCRIPT
// Town 2: New Town

// This is the special encounter script for this town.

begintownscript;

variables;

int choice;

body;

beginstate INIT_STATE;
// This state is called whenever this town is entered.
enable_add_char(0);
set_crime_tolerance(2);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
message_dialog("You walk out of New Town, curious as to what adventures you can find!"," ");
break;

begingstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate11;
reset_dialog();
add_dialog_str(0, "You see a beggar holding out a tin cup to you. _Could you please spare a few coins so I can eat?_" 0);
add_dialog_choice(0, "Yes I will. (Give him coins)");
add_dialog_choice(1, "Sorry, I don't have any myself.");
add_dialog_choice(2, "Back off old man and leave me alone!");
choice = run_dialog(0);
if (choice == 1) {
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
}
else if (choice == 2) {
message_dialog("He sighs and sulks away."," ");
}
else {
message_dialog("He spits in your face and walks away, muttering about how young people only think of themselves these days."," ");
}
break;


--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
Warrior
Member # 5861
Profile Homepage #7
Thank you, thank you, thank you, thank you, thank you, thank you!!! Ok, so anytime your going to use anything as a variable that's how you declare it? Ok, now I know. That was something else I was confused about. Like I said, bear with me - it's been a long time since I've done any sort of programming, and this is my first time with Avernumscript. Thanks again for the help guys!
Posts: 72 | Registered: Sunday, May 29 2005 07:00
BANNED
Member # 4
Profile Homepage #8
You still don't have a check for the party's actual coins. Here:

// TOWN SCRIPT
// Town 2: New Town

// This is the special encounter script for this town.

begintownscript;

variables;

int choice;

body;

beginstate INIT_STATE;
// This state is called whenever this town is entered.
enable_add_char(0);
set_crime_tolerance(2);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
message_dialog("You walk out of New Town, curious as to what adventures you can find!"," ");
break;

begingstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate11;
reset_dialog();
add_dialog_str(0, "You see a beggar holding out a tin cup to you. _Could you please spare a few coins so I can eat?_" 0);
add_dialog_choice(0, "Yes I will. (Give him coins)");
add_dialog_choice(1, "Sorry, I don't have any myself.");
add_dialog_choice(2, "Back off old man and leave me alone!");
choice = run_dialog(0);
if (choice == 1) {
if(coins_amount() >= 10){
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
}
else{
message_dialog("When he sees that you yourself don't have enough coins to give him, he looks rather ashamed of himself.","");
}
}
else if (choice == 2) {
message_dialog("He sighs and sulks away."," ");
}
else {
message_dialog("He spits in your face and walks away, muttering about how young people only think of themselves these days."," ");
}
break;
This way, if the party doesn't actually have 10 coins, it doesn't say that the party gives the beggar 10 coins.

Alternatively, you could call the change_coins() call and then check to see if the party has 0 or fewer coins afterwards- if so, then you can have the party give the beggar as many coins as they are able.

--------------------
*
Posts: 6936 | Registered: Tuesday, September 18 2001 07:00
Warrior
Member # 5861
Profile Homepage #9
Here it is fixed, and it works:

// Town 2: New Town

// This is the special encounter script for this town.

begintownscript;

variables;

int choice;
body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
enable_add_chars(0);

// Names must appear first.
set_name(11,"Jean");

set_crime_tolerance(2);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
message_dialog("You walk out of New Town, curious as to what adentures you can find!"," ");
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 11;
reset_dialog();
add_dialog_str(0, "You see a beggar holding out a tin cup to you. _Could you please spare a few coins so I can eat?_" 0);
add_dialog_choice(0, "Yes I will. (Give him coins)");
add_dialog_choice(1, "Sorry, I don't have any myself.");
add_dialog_choice(2, "Back off old man and leave me alone!");
choice = run_dialog(0);
if (choice == 1) {
if (coins_amount() == 0) {
message_dialog("When he sees that you yourself don't have enough coins to give him, he looks rather ashamed of himself."," ");
}
else {
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
}
}
else if (choice == 2) {
message_dialog("He sighs and sulks away."," ");
end();
}
else {
message_dialog("He spits in your face and walks away, muttering about how young people only think of themselves these days."," ");
}
break;
Thanks for the help guys! I've just finished creating dialog for two shops!! I think I'm getting a hang of this!! I doubt I'll have much time to work on it the next three weeks because of school, but I do have another question (surprise surprise). How do I make the outer walls of the city taller?? When my party is actually in the city, they look taller than the city walls! And, how can you put items inside things like crates, bookshelves, desks, etc....???

[ Sunday, November 27, 2005 18:12: Message edited by: iluvhorses ]
Posts: 72 | Registered: Sunday, May 29 2005 07:00
Off With Their Heads
Member # 4045
Profile Homepage #10
If you mean the walls of the city that are still inside the town, you go to Town Details and set the height of the wall. If you mean outdoors, you have to use a custom graphic, and I don't think one like that exists yet.

Putting things inside containers is easy. Put them on top of the container. Make sure that they say Contained (down by Property/Not Property) — this is their default state. You won't see any difference in the editor, but they're contained.

--------------------
Arancaytar: Every time you ask people to compare TM and Kel, you endanger the poor, fluffy kittens.
Smoo: Get ready to face the walls!
Ephesos: In conclusion, yarr.

Kelandon's Pink and Pretty Page!!: the authorized location for all things by me
The Archive of all released BoE scenarios ever
Posts: 7968 | Registered: Saturday, February 28 2004 08:00
? Man, ? Amazing
Member # 5755
Profile #11
choice = run_dialog(0);
COINS = COINS_AMOUNT(); // define coins as integer
if (choice == 1) {
if (COINS < 10) { // Not 0, but 10
message_dialog("When he sees that you yourself don't have enough coins to give
him, he looks rather ashamed of himself."," ");
message_dialog("Clearly this fellow is needy and humble, so you toss him your last coins."," ");
change_coins(-1*coins);
}
else {
change_coins(-10);
message_dialog("He thanks you profusely and walks to the nearest bakery."," ");
}
}
Otherwise your 4 coins turns into a negative. I think you can use arithmetic in the change_coins command, but may be wrong. You can make a new variable if I am wrong.

*this message sponsored by the Shayder Chamber of Commerce*

--------------------
quote:
Originally written by Kelandon:

Well, I'm at least pretty sure that Salmon is losing.


Posts: 4114 | Registered: Monday, April 25 2005 07:00
...b10010b...
Member # 869
Profile Homepage #12
It isn't really necessary to define coins as a variable -- using coins_amount() in the conditional statement is fine.

--------------------
The Empire Always Loses: This Time For Sure!
Posts: 9973 | Registered: Saturday, March 30 2002 08:00
Warrior
Member # 5861
Profile Homepage #13
Kelandon - I got the wall thing figured out - I just used different walls :) And thanks for the tip on putting things inside of stuff. I thought that the contained/not contained meant that they were already contained somehow, like potions in a bottle.

Thanks for trying to help, Jumpin' Salmon - but right now I'm trying to avoid confusion at all costs, so I'm just taking baby steps until I get this all figured out - but it was a really good tip, I'll have to keep it in mind for the future!
Posts: 72 | Registered: Sunday, May 29 2005 07:00