Answering an NPC's question with pop-up?

XanMag
I need help and apologize if I've missed this somewhere else in the forum.

I want an NPC to ask the question "Who's there?" (which I CAN do =),

but I want to force the player into typing a response to that question.

In my first game I did a round-about solution by basically telling the player that they need to simply type answer #text#, so the player knew to type 'answer blah blah blah'. But the problem with that is the player could leave the room or ignore typing a response if they chose to. I did this through the + command option. This time, I want to force the player to answer the question and not let them wimp out by ignoring it. Of course, I would need consequences for acceptable and unacceptable answers which I think I can figure out.

So, in short, I need to know how to have a pop-up box (or mandatory get input option) where the player must type something in to answer the question. I do NOT want it to be a multiple choice option though.

And remember... I'm currently a GUI'er rather than a coder!

Also... reminder... 'Xanadu' is still out there waiting calmly to be played:!:

Thanks in advance!

XanMag

HegemonKhan
you already are aware of the harder more complex method (Commands) out of only two ways to get input from the person playing the game, and the other, simplier method is:

http://docs.textadventures.co.uk/quest/ ... input.html

and here's a GUI~Editor step by step guide on this, via using a 'character creation' sample example:

http://docs.textadventures.co.uk/quest/ ... ation.html

since this will be a script block, the person will be locked into it (you'll need to set up your script block properly, of course).

general structure of what you'll want to do:

msg ("your_question")
get input {
// quest automatically (hidden from you) sets its built-in Variable: result = your_typed_in_input
if (result OPERATOR Value_or_Expression) {
// whatever script(s)
} else if (result OPERATOR Value_or_Expression) {
// whatever script(s)
} else {
// whatever script(s)
}
}


---------------

here's an example:

<function name="human_age_integer_attribute_function" parameters="character_parameter"><![CDATA[
msg ("Age? (Type in a number within: 0 to 120)")
get input {
if (IsInt (result) and ToInt (result) >= 0 and ToInt (result) < 120) {
character_parameter.age_integer_attribute = ToInt (result)
ClearScreen
} else {
ClearScreen
human_age_integer_attribute_function (character_parameter)
}
}
]]></function>


-------------

if you want to test~play this out:

viewtopic.php?f=18&t=4988

let me know if it doesn't work, or whatever else, lol.

-------------

if you want~need an actual popup menu window... I only know of using 'show menu' ( http://docs.textadventures.co.uk/quest/ ... _menu.html ), but maybe Jay~Pixie~etc, can help you with the coding to produce your own popup menu window, (I myself would like a popup menu window, but am not sure if I can use the 'show menu' for what I want from it... so if Jay~Pixie~etc can figure out a way, code in, to make a popup menu window, I'll be very interested in it as well, hehe. I want to have hyperlinks, where you click on them, and a popup menu window displays, and after you read it, you go back to the previous text. This is how I want to implement my 'pedia' system. For example, before you select you gender, you can Command~hyperlink click on 'male' and 'female', getting a popup window that tells about them, for example 'males' get an extra +1 strength and +1 endurance at every lvlup and females get an extra +1 dexterity and +1 agility at every lvlup, and then when done reading it, you return to the gender selection text. Maybe this can be done with the 'show menu', but I've just not yet started to experiment-test with it yet).

The Pixie
Take a look at this "How to" article, "Ask a question". It does not give a pop-up (as HK says, you cannot do that with typed input), but does change the command box to make it only accept the answer, rather than another command.

It is in code, but you can paste the code (copy the one at the bottom of the page) into your game, then go to GUI view and modify it there.

ETA: I realise I forgot to put in the actual link:
http://docs.textadventures.co.uk/quest/ ... stion.html

XanMag
Whew...

I finally got it to work. Thanks HK and Pixie.

I tinkered with it for far too long and realized that I forgot my quotation marks around my results!?!

if (result = "Joey Smith") <--- those quotes!!! ARGH!

Thirty minutes for a pair of quotes!!! Coding is a finicky S.O.B.! lol

Also, before my brain explodes... How do I write it so that there could be multiple correct answers and multiple incorrect answers? Say, I want to allow the player to use "Joe" or "Mr. Smith" or "Joey" and be correct. Or, I want "Dingo" to give a different wrong answer than "Xanadu"?

Thanks in advance!

TinFoilMkIV
My syntax may not be correct on this, but you will likely wan to use the "or" symbol '|' to setup a case for a limited set of answers. Note that is a vertical bar not an 'L' or an 'i'.

It should look something like this

msg ("your_question")
get input {
if (result = "(Joe|Joey|Mr. Smith)" ){
// right answer stuff here
} else if (result = "(SomeOtherPerson|OtherSpecificPerson)") {
// wrong but special result
} else {
// generic wrong answer
}
}


EDIT:
And of course right after I post that I remember that this is the perfect situation to use a 'Switch'. A Switch basically takes a value, in your case the 'result' from the player input. and performs a different block of code if it matches any of the defined cases. Also has built in functionality for multiple answers getting the same result. It will look something like this
switch (result) {
case ("Joe", "Joey", "Mr. Smith") {
msg ("right answer!")
}
case ("Xanadu") {
msg ("close, but no...") {
}
case ("Dingo") {
msg ("hmmm... nope, still wrong")
}
case ("asdfg") {
msg ("get out...")
MoveObject (player, death pit)
}
default {
msg ("wrong answer")
}
}

XanMag
Wow. I've toyed with it and I dare say I understand these scripts now! This has opened up a ton of other possibilities (not to mention an increased game depth) for my works in progress. I'm now motivated to continue the process. Thank you all a ton and I hope to get "Xanadu 2" out sooner rather than later! WOO-HOO!!

TinFoilMkIV
No problem, and glad to hear that. Switches really are quite handy when you get used to using em, I honestly can't believe I forgot about that when I initially posted.

The Pixie
XanMag wrote:Also, before my brain explodes... How do I write it so that there could be multiple correct answers and multiple incorrect answers? Say, I want to allow the player to use "Joe" or "Mr. Smith" or "Joey" and be correct. Or, I want "Dingo" to give a different wrong answer than "Xanadu"?

That is covered in the "How to" I failed to link to:
http://docs.textadventures.co.uk/quest/ ... stion.html

TinFoilMkIV is almost there, but you need the IsRegexMatch function to do the comparison.

HegemonKhan
if your Attribute is to be a String Attribute, then you must have its Value be encased in double quotes (or if you got an Expression, the textual parts must be encased in double quotes), this is because:

(ya it's very annoying to remember: I've had the same situation myself, trying to trouble shoot for hrs only to finally realize it was because I forgot to use double quotes, and~or confusing too if you're still learning to code)

no double quoted (non-numerical) Value (except for 'true' and 'false' as these are reserved for~as the Boolean Attribute's Values), tells quest engine that its Value is an actual Object (and not just a String Attribute's String Value):

player.lunchbag_object_attribute = apple

<object name="apple_object_1">
<alias>apple</alias>
</object>

<object name="player">
<attr name="lunchbag_object_attribute" type="object">apple_object_1</attr>
</object>

// an Object and an Object Attribute, are two different things. An Object is well an actual Object, lol. Whereas, an Object Attribute is an Attribute which HOLDS an Object, as its Value.

// the best analogy Object Attribute: player.right_hand = sword


no double quoted (numerical) Value, tells the quest engine that it is an Integer Attribute:

player.strength = 50

a quoted Value tells the quest engine that it is a String Attribute:

player.favorite_food = "apple"
player.favorite_number = "7"

-----------

to re-cap:

player.food_string_attribute = "apple"

VS

player.food_object_attribute = apple
<object name="apple">
</object>

------------

to re-cap:

player.number_integer_attribute = 7
// this Value is an actual number, so it can be used to do computation (addition, subtraction, multiplication, division, and comparisons: greater than, lesser than, and etc) Expressions

VS

player.number_string_attribute = "7"
// this is NOT an actual number Value, so you can NOT use it to do computation Expressions

----------

you can convert between a String Attribute and an Integer Attribute:

player.number_integer_attribute = ToInt (player.number_string_attribute)
// 7 <===== "7"

player.number_string_attribute = ToString (player.number_integer_attribute)
// "7" <===== 7

----------

another syntax method, an example (using 'or' conditionals):

msg ("What is your name?")
get input {
if (result = "joe" or result = "jeff" or result = "jim" or result = "john") {
player.gender_string = "male"
} else if (result = "jennifer" or result = "jessisca" or result = "jasmine") {
player.gender_string = "female"
} else {
player.gender_string = "asexual"
}
}


-------

another method, is to use List Attributes instead:

if (ListContains (player.witch_pot_objectlist, toad) and ListContains (player.witch_pot_objectlist, rat) and ListContains (player.witch_pot_objectlist, mushroom)) {
// (after drinking the brew) you turn into a ...
} else if (ListContains (player.witch_pot_objectlist, cat) and ListContains (player.witch_pot_objectlist, dog) and ListContains (player.witch_pot_objectlist, pig)) {
// (after drinking the bew) you turn into a ...
}


-----------------

do read up on 'and', 'or' ( 'XOR' ~ exclusive or ), and etc conditionals, to understand their usage, if you don't already know aobut them.

you can use parenthesis, to control the 'order of operations' and via doing groupings, just like you do with~in math, for 'and' and 'or' conditionals too.

---------------

though as you can see, these quest~XML syntax methods are much more typing than using the 'regex and the | symbol' syntax methods that more common programming languages use (and quest can use them too), that Pixie and TinFoil talk about in their posts.

--------------

P.S.

@Xanadu:

welcome to the 'fun' (sarcasm) of trouble-shooting ~ diagnosing... !!! :D

though, if you can successfully trouble shoot, it's proof~verification that you ARE learning to code, hehe :D

and... 90% of the time, usually the $@$#@ problem is some stupid simple typo or missing character~symbol... which is a relief in that you got the code design correct, but also a huge irritant that you spent that much time, just to find and fix something so stupid and simple, laughs. I mean if you spend hrs, the problem should be a major flaw in your code design, and you just amazingly fixed it up, into a beautiful code design, hehe. But often your code design is fine... and it's just something stupid~simple... but finding the thing... usually does take a long time... ARGH~GRRR !!!!

(though the error codes help, as they tell you the line and character of the problem... hehe, and if you use text software, such as notepad++, that tells the mouse~cursors, line and character location, then it helps to speed up the trouble shooting, immensely)

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums