Jump to content

Stupid Question


Recommended Posts

New question: Here is some scripting I wrote for my practice scenario. It works, but for some reason keeps reactivating. What I mean is, when you pull the lever for the first and what should be only time, everything works. But when you step on the lever again you get the message

Quote:
"You pull the lever. At first nothing seems to happen, then something spawns on the pentagram."

Nothing else happens. The demon doesn't spawn, the sound effect doesn't go off, nothing. But the message comes up every time you walk over the lever. Here is my code:

 

Code:
 beginstate 12;	if (get_flag(2,3) <= 0) {		reset_dialog();		add_dialog_str(0,"An innocent lever sits in the floor.",0);		add_dialog_str(1,"Pull it?",0);		add_dialog_choice(0,"Yes");		add_dialog_choice(1,"No");		}			if ((run_dialog(0) == 1) && (get_flag(2,3) <= 0)) {				play_sound(99);				set_terrain(18,10,375);				set_terrain(15,12,33);				set_flag(2,3,1);				set_state_continue(13);				}break;beginstate 13;	if (get_flag(3,3) <= 0) {		message_dialog("You pull the lever.","At first nothing seems to happen, then something spawns on the pentagram.");		place_monster(20,8,59,1);		put_effect_on_space(20,8,10,4,1);		set_flag(3,3,1);		}break; 
To keep my question simple, WTF?
Link to comment
Share on other sites

Just curious on a couple things:

 

1) Why don't you enclose the second half of state 12 into the first, i.e. nest the second conditional in with the first, that way it never gets seen if 2,3 is > 0.

 

2) Why are two seperate states required. It seems like the flag 3,3 is used unnecessarily. This is, of course, assuming you have shown us all that relates to this encounter.

 

3) I usually put the result of run_dialog() in another variable, typically called "choice". I don't think it matters, but I've had weird things with dialog at times.

Link to comment
Share on other sites

If you use the original specobj script for the lever, memory cells 2 and 3 are the coordinates of a flag that, when set to 1, prevent the event from happening. So... set mem cell 2 =2 and mem cell 3 = 3 to prevent the lever from being used again.

 

EDIT: flag (3,3) does seem to be unnecessary to this section of script.

Link to comment
Share on other sites

Quote:
If you use the original specobj script for the lever, memory cells 2 and 3 are the coordinates of a flag that, when set to 1, prevent the event from happening. So... set mem cell 2 =2 and mem cell 3 = 3 to prevent the lever from being used again.
It's little important facts like these I wish were put in big bold letters somewhere easy to find.

Question: I set the memory cells on the lever to my SDF. Does this mean I dont have to use the call set_flag(2,3,1)?

Edit: And because I used the specobj script on the lever, do I not have to place special encounter over it?
Link to comment
Share on other sites

The documentation is confusing, isn't it. If I was an old member who'd been here for years, I'd probably post a link to some site that explains it all perfectly.

I'm pretty sure that you do need to use the set_flag call- the mem cells are only used to say which flag prevents the event, not which flag to set to 1-you'd need to write your own object script for that.

I'm also sure that you don't need a special encounter. If I'm wrong, please tell me. smile

Link to comment
Share on other sites

Okay, if you use a specobj script, you don't need a special encounter on the lever's space. As for the code itself, I see issues. (see comment)

 

Quote:
Originally written by Enraged Slith:

Code:
 beginstate 12;	if (get_flag(2,3) <= 0) {		reset_dialog_preset_options(2);		run_dialog(0) == 2;		play_sound(99);		set_terrain(18,10,375);		set_terrain(15,12,33);		set_flag(2,3,1);		message_dialog("You pull the lever.","At first nothing seems to happen, then something spawns on the pentagram.");		put_effect_on_space(20,8,10,4,1);		place_monster(20,8,59,1);		} 

What was the line "run_dialog(0) == 2;" intended to do? Because in here, all it will do is run the dialogue box, without taking the player's input.
Link to comment
Share on other sites

run_dialog() runs the dialog that has been constructed by using the add_dialog_string(), add_dialog_choice(), and all the preset dialog functions. If you put a 1 in the parentheses, the "record" button will appear when the dialog is displayed, a zero will omit the button.

 

As for what the function returns, if there's only one choice (say, "Okay."), the function will just return a 1, since that's the number of the choice. For more than one choice, it will return different numbers depending on what choice the player picks. Say I've got this set up:

 

Code:
short choice = 0;reset_dialog();add_dialog_str(1,"Pointless drivel.",0);add_dialog_choice(0,"Fish.");add_dialog_choice(1,"Pi.");choice = run_dialog(1);
"Pointless drivel" will appear with the choices and a Record button. If the player picks "Fish", run_dialog() will return a '1', thus making choice equal to 1. (Note, the function returns a number one higher than the number given in add_dialog_choice().)

 

If the player picks "pi", then the function returns a 2.

 

I hope that cleared things up. Class is dismissed.

Link to comment
Share on other sites

Thanks for clearing up the function of run_dialog(), however, one thing about it still bugs me.

 

The phrase "choice = run_dialog(1);". What is the function of choice = and why change the variable from '0' in the first place? Wouldn't saying choice = run_dialog(1) be the same as saying

0 = run_dialog(1)? So what would 0 = run_dialog() mean? Isn't '0' preset to false?

And when writing the next part of the script

Code:
 if (choice == 2) // or (0 == 2)and '2' just being an example of an answer. 
Wouldn't that basically be saying if (FALSE)? I'm running on low sleep and this problem is driving me crazy. Please clarify.

 

A less involved question: What exactly is the function of 'end()' and when would it be used?

Link to comment
Share on other sites

The idea is that "choice = run_dialog(1)" sets the variable "choice" to whatever the value of run_dialog is. It's like saying "choice = 1" or "choice = 2" or whatever. (You work right to left, so BoA turns the run_dialog into a number and then sets choice to that number.)

 

So "choice" starts out as 0 in the beginning of the script — this is unnecessary; you could take it out and just say "short choice;" — and then it gets set to whatever the run_dialog returned (either 1 or 2, depending on what the player chose). That way, when you run your "if" business, the "choice" variable is either 1 or 2.

 

And "end" is used when you want everything to stop right away. I have an example of this in an article — "end" is under One-Shot Specials.

Link to comment
Share on other sites

Quote:
The phrase "choice = run_dialog(1);". What is the function of choice = and why change the variable from '0' in the first place? Wouldn't saying choice = run_dialog(1) be the same as saying
0 = run_dialog(1)? So what would 0 = run_dialog() mean? Isn't '0' preset to false?
The variable 'choice' is a placeholder variable and useful as it is more or less fixed until changed or entering a new area. Run dialog is a specific function that does two things:

1) It brings up the dialogue message allowing the player to see it and choose.
2) It returns the choice that the player gave. Note that run_dialog() does not have an intrinsic value in itself...it is a function, not a variable.

I'd suggest assigning first and not putting run_dialog() in a logical test as it may or may not get evaluated depending on the order of operations and the coding Jeff used on how the boolean statements are evaluated. In other words, if one of the conditions is determined false in an AND construct, it could just skip evaluating the other because it "knows" the entire statement is false. In such case, the player would see no message at all. Of course, the coding could have that all values are checked regardless of the logic meaning this would not be the case.

'0' is an integer value and not generally the same as false. For a boolean or logical type variable, 0 may mean false in some languages. However, 0 and false should not be equated as the same. In your case, 'choice' is an integer variable so that the meaning of 0 is indeed the number zero, not false.

0 = run_dialog() would mean that you are attempted to reassign the integer value of zero, which is not allowed. Assignment is done with the variable to be operated on on the left -- don't confuse assignment equals with the mathematical equals, there is a subtle difference that I just pointed out.
Link to comment
Share on other sites

Quote:
Originally written by *i:
I'd suggest assigning first and not putting run_dialog() in a logical test as it may or may not get evaluated depending on the order of operations and the coding Jeff used on how the boolean statements are evaluated.
I think, in this case, he's okay. I usually put run_dialog in an "if" phrase unless I have three options to choose among, and it's safe as long as the run_dialog is in the first condition, I believe.

The reason, apparently, is that BoA reads right-to-left inside expressions but left-to-right outside them. Or something. :rolleyes:
Link to comment
Share on other sites

Thank you, that cleared a lot of things up.

Code:
 beginstate 12;	if (get_flag(2,3) <= 0) {		reset_dialog_preset_options(2);		choice = run_dialog(0);		}		if (choice == 2) {			play_sound(99);			set_terrain(18,10,375);			set_terrain(15,12,33);			set_flag(2,3,1);			message_dialog("You pull the lever.","At first nothing seems to happen, then something spawns on the pentagram.");			put_effect_on_space(20,8,10,4,1);			place_monster(20,8,59,1);			}break; 
Is this more or less what it should look like now? Note that I set 'choice' as a variable earlier in the town script.

 

Edit: And yes I did read the one-shot specials section, but I'm going to stay away from 'end()'for the time being until I get a better handle on scripting.

Link to comment
Share on other sites

You also have to run the effect. Stick a run_animation or run_animation_sound at the end, perhaps after you've placed the monster.

 

By the way, if you place the monster first and use a hidden group (which I always prefer over place_monster whenever possible, for a variety of reasons), you can use put_effect_on_char instead of specifying the space.

Link to comment
Share on other sites

New question:

 

I am designing a practice town with a lot of puzzles, SDFs, and combinations. I am trying to make an altar that kills a character of your choice if he doesn't have enough (stat). Please help me fill in this code (or fix whatever I screwed up).

 

Code:
 beginstate 14;	// select character	// selected character = ME		reset_dialog()		add_dialog_str(0,"blah blah.",0);		add_dialog_str(1,"blah blah.",0);		add_dialog_str(2,"Rest on the altar?");		add_dialog_choice(0,"Try to resist");		add_dialog_choice(1,"Rest on the altar.");		choice = run_dialog();			if ((choice = 1) && (get_stat(ME,2) >= 6)) {				message_dialog("blah blah.","");				end();				}				else {					message_dialog("Blah blah.","");					kill_char(ME,2,0);					end();					}			if (choice = 2) {				message_dialog("Blah blah.","");				kill_char(ME,2,0);				end();				}break; 
Edit: Mainly I want you to correct any large errors and fill in what I need at the top. I've already found most of the small errors and typos.
Link to comment
Share on other sites

ME is a reserved constant, defined equal to -1, except when running a creature (or terrain? I can't remember.) script. You need a different variable name I think. Also, you can get the selected pc with a get_selected_char() call. Or, you can ask the player to selecta pc with run_select_a_pc() and get_selected_pc(). It might also be a nice touch to alter the strings so that the player is asked "Do you want [name of selected character] to rest on the alter?" and so forth. You can do this with the string manipulation calls without too much trouble.

Link to comment
Share on other sites

The call run_dialog needs arguments (probably the number "1").

 

You don't need the "end" calls.

 

As Niemand indicated, you'll need a real variable, not ME.

 

I'd go with something like this at the top (much like what Niemand described):

 

Code:
 message_dialog("Something about needing to select a person.","");if (run_select_a_pc(0) == 0)	message_dialog("You fail. At life.","");else {	} 
Within the "else" part, you can put the rest of your code, and instead of ME, use get_selected_pc().
Link to comment
Share on other sites

  • 2 weeks later...

New question, sort of. I looked back over this town script and figured out why I was having trouble with a certain state. However, I can not think of a different way to write it out. Basically this is what I have written:

Code:
 beginstate 14;	run_select_a_pc(0);	bob = get_selected_pc();	reset_dialog();	add_dialog_str(0,"addfstyjkujk,"0);	add_dialog_str(1,"a;lsjkdflasf;asdf.",0);	add_dialog_str(2,"Bibbity?",0);	add_dialog_choice(0,"no bibbity");	add_dialog_choice(1,"bibbity.");	choice = run_dialog(1);		if ((choice == 1) && (get_stat(bob,2) >= 6)) {			message_dialog("I touched the applesauce.","");			}			else {				message_dialog("mango","woogity woogy.");				kill_char(bob,2,0);				}		if (choice == 2) {			message_dialog("blah","wakka wakka.");			kill_char(bob,2,0);			}break; 
The problem here was that when your character selected the second choice, the first choice ELSE message would play, and then the second message would play. I know now that ELSE is called whenever the IF requirements are not met.

 

How can I make it so that Choice 1 has two possible outcomes while Choice 2 is also a possible outcome.

Link to comment
Share on other sites

What you want is:

Code:
 if(choice == 1){   if(something){      //do stuff   }   else{      //do other stuff   }}else if(choice == 2){   //do different stuff}
The problem was that you combined two conditions into one if statement, so that the else block occurred if either was false, when you wanted it to occur when only a specific one was false.

 

EDIT: How did I mispell 'that' as 'htta'?

Link to comment
Share on other sites

Quote:
Originally written by Enraged Slith:
choice = run_dialog(1);
if ((choice == 1)
{ if(get_stat() >= x)
message_dialog("I touched the applesauce.","");

else {
message_dialog("mango","woogity woogy.");
kill_char(bob,2,0);
}
}

You need brackets after the if(choice == 1).
Edit: Note to self, don't use tab when posting.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...