Talking to NPC's and stuff

dado1996
25 Mar 2016, 03:59
Probably the dumbest questions, but I'm pretty new at this. So, how do you change dialog on NPC's after you have talked to them once?

And how do you give them objects from your inventory, or receive objects from them?

XanMag
25 Mar 2016, 10:06
Check this out: viewtopic.php?f=10&t=5973

Also, check out 'Quest - Tutorials and Templates'. It's a game that I created that is meant to guide game creators through common problems/questions they have. It is specifically designed to be useful for those who don't really do coding. There are several rooms in there dedicated to NPC interaction.

In the meantime, for changing NPC responses after talking with them once, you can either use the First Time script or check for a flag. The best option depends on if you want new topics to appear or new content on old topics to appear!

Certainly, if you need clarification, I'll help later when I'm sitting in front of my computer. Good luck!

dado1996
25 Mar 2016, 15:32
Thanks a lot. Also, would you mind telling me how to print different text depending on the choice on a menu?

XanMag
25 Mar 2016, 17:41
You want a pop-up menu or a "homemade" menu? I can help you with the homemade version but have no experience with pop-ups. Let me know.

dado1996
25 Mar 2016, 17:44
I'm actually using a pop-up menu, because that's the only one I know. But if you have no problem explaining the homemade I'll use that

HegemonKhan
25 Mar 2016, 17:54
the key thing to understand with popup menus ('show menu') is that your list-menu selection choice is set to the variable 'result', so for example in code:

show menu ("What is your sex?", split ("male;female", ";"), false) {
// 'male' or 'female' menu-list choices
// quest automatically (hidden from you), sets the variable: result = <your selected choice from the menu-list>
// ie, for me, I'd choose 'male', so it would be: result = "male"
switch (result) { // this is telling the 'switch' Function/Script to use/examine the variable 'result'
case ("male") { // if the 'result' Variable's Value is "male", then do the scripts below:
player.sex = "male"
msg ("You chosen to be a male.")
}
case ("female") { // if the 'result' Variable's Value is "female", then do the scripts below:
player.sex = "female"
msg ("You chosen to be a female.")
}
}
}


the 'switch' Function/Script is the same as using an 'If' Script block:

show menu ("What is your sex?", split ("male;female", ";"), false) {
// 'male' or 'female' menu-list choices
// quest automatically (hidden from you), sets the variable: result = <your selected choice from the menu-list>
// ie, for me, I'd choose 'male', so it would be: result = "male"
if (result = "male") {
player.sex = "male"
msg ("You chosen to be a male.")
} else if (result = "female") { // actually this should just be an 'else', as its a dualism choice: if (male) then you're a male, else: you're female). 'else ifs' are only needed if you have more than 2 choices
player.sex = "female"
msg ("You chosen to be a female.")
}
}


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

see this guide for examples using the GUI~Editor:

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

XanMag will otherwise be able to help you, if you still need help.

HegemonKhan
25 Mar 2016, 18:09
As to the actual dynamic dialogue issue, that is a lot more complex... I'd check out libraries/codes by Pixie and other good coders, than trying to craft your own, as dialogue is very advanced.

think of it in the most simple of terms:

('dialogue_state' is an Integer Attribute)

npc1
dialogue_state: 0

npc2
dialogue_state: 0

npc3
dialogue_state: 0

----------

npc1:

dialogue_state 0:

"Hi, my name is npc1" -> npc1.dialogue_state = 1

dialogue_state 1:

if (npc3.dialogue_state = 0) then "I don't have anything to say to you until you go talk to npc3"
else if (npc3_dialogue_state = 1) then "ah yes I am npc3's brother" -> npc1.dialogue_state = 2

dialogue_state 2:

blah blah blah

dialogue_state 3:

blah blah blah

npc2:

dialogue-state 0:

etc etc etc

npc3:

blah blah blah

hopefully you get the idea...

-------

this most simple dialogue handling design (incrementing/adjusting a dialogue state for each npc based upon conditions and if-checking it each time), is very inefficient/cumbersome, which is why you should use the libraries of the better coders here, like Pixie's and others'.

dado1996
25 Mar 2016, 18:34
HegemonKhan That is very helpful and I appreciate it. Now I want to know if in the switch case, there is no problem if I use more than one word in the split.

The Pixie
25 Mar 2016, 18:54
Check out the library, which does pretty much what you want:
viewtopic.php?f=18&t=5510

HegemonKhan
25 Mar 2016, 20:11
dado1996 wrote:HegemonKhan That is very helpful and I appreciate it. Now I want to know if in the switch case, there is no problem if I use more than one word in the split.


the 'split' Function/Script is a quick way to create a list:

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

this is it's syntax/format:

(you can have as many word/phrase items as you want, I'm just using 3 below)

split ("word/phrase item 1 SEPARATOR word/phrase item 2 SEPARATOR word/phrase item 3", "SEPARATOR")

the usual convention is:

SEPARATOR: semicolon character/symbol // but you can use generally whatever character/symbol you want, if you prefer

so, for example:

// the concept of split:
// 'redblueyellow' String is "split" up into 3 sub/new-Strings: 'red', 'blue', and 'yellow'

and when using 'split' with 'show menu', you get:

single word items: split ("red; blue; yellow", ";")
// output popup menu choices:
// red
// blue
// yellow

~ OR ~

// the concept of split:
// 'You love the color red You love the color blue You love the color yellow' String is "split" up into 3 sub/new-Strings: 'You love the color red', 'You love the color blue', and 'You love the color yellow'

phrase items: split ("You love the color red; You love the color blue; You love the color yellow", ";")
// output popup menu choices:
// You love the color red
// You love the color blue
// you love the color yellow

though if you use phrases, then your if/switch-case Scripting has to match those phrases (just as they have to match when you use single words):

(the "arrows" aren't proper code syntax, I just use them to do/show the intenting/"nesting", when I don't want to use the post's code boxes)

switch (resut)
-> case ("You love the color red") {
->-> // scripts
-> }
-> case ("You love the color blue") {
->-> // scripts
-> }
-> case ("You love the color yellow") {
->-> // scripts
-> }
}

OR

if (result = "You love the color red") {
-> // scripts
} else if (result = "You love the color blue") {
-> // scripts
} else if (result = "You love the color yellow") {
-> // scripts
}

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

when an Attribute's Value is encased within double quotes, quest understands that Value to be a String Value, which means that the Attribute must be a String Attribute too (String Attributes hold String Values).

GUI~Editor's Adding (creating) an Attribute (non-scripting method):
(Object Name: player)
Attribute Name: favorite_fruit
Attribute Type: string
Attribute Value: apple // the GUI-Editor handles it, so you don't need to put in the double quotes yourself

Scripting method:

player.favorite_fruit = "apple" // this is just refering to specific TEXT (text/string: "apple"), not an actual-existing 'apple' Object.

VS

when an Attribute's Value is NOT encased within double quotes, quest understands that Value to be an Object Value, which means that the Attribute must be an Object Attribute too (Object Attributes hold Object Values).

<object name="apple">
-> contents/attributes
</object>

GUI~Editor's Adding (creating) an Attribute (non-scripting method):
(Object Name: player)
Attribute Name: favorite_fruit
Attribute Type: object // this means the Attribute is an Object Attribute; an Attribute that holds an Object Value (the name/ID of the Object, not the actual-physical Object itself. Think of this as like a P.E. roster. The roster-paper holds the name of the students, not the students, lol. However, the PE coach can use the roster to bark orders to those students, which is what makes Object Attributes useful. Object Attributes only hold a single Object Value, Object List Attributes can hold any qunatity of Object Values)
Attribute Value: apple // the GUI-Editor handles it, so you don't need to worry about whether it needs double quotes or not (it doesn't, it's not a string)

Scripting method:

player.favorite_fruit = apple // this is refering to the actual (and existing) Object: <object name="apple">contents/attributes</object>

-----------

a more meaningful example of Object Attributes is this example:

<object name="unarmed">
-> <attr name="damage" type="int">1</attr>
</object>

<object name="katana">
-> <attr name="damage" type="int">50</attr>
</object>

<object name="claymore">
-> <attr name="damage" type="int">75</attr>
</object>

<object name="battle_axe">
-> <attr name="damage" type="int">100</attr>
</object>

<object name="player">
-> <attr name="right_hand" type="object">unarmed</attr>
-> <attr name="damage" type="int">player.right_hand.damage + player.right_hand.damage * player.strength / 100</attr>
</object>

in scripting:

unarmed.damage = 1
katana.damage = 50
claymore.damage = 75
battle_axe.damage = 100
player.strength = 67

player.right_hand = unarmed // you're initially "equipped" with unarmed (conceptually not equipped with a weapon)
player.damage = player.right_hand.damage + player.right_hand.damage * player.strength / 100
// player.damage = 1 + ( 1 * (67/100) )

player.right_hand = katana // you "equipped" the katana
player.damage = player.right_hand.damage + player.right_hand.damage * player.strength / 100
// player.damage = 50 + ( 50 * (67/100) )

player.right_hand = claymore // you "equipped" the claymore
player.damage = player.right_hand.damage + player.right_hand.damage * player.strength / 100
// player.damage = 75 + ( 75 * (67/100) )

player.right_hand = battle_axe // you "equipped" the battle_axe
player.damage = player.right_hand.damage + player.right_hand.damage * player.strength / 100
// player.damage = 100 + ( 100 * (67/100) )

notice how the player posseses none of the 4 weapon Objects in his/her inventory (none of the 4 weapons are on/inside of the 'player' Player Object) nor held inside of the 'right_hand' Object Attribute of the player's, yet we're able to use them for determining the 'player' Player Object's 'damage' Integer (int) Attribute, through the Object Attribute.

just has the PE coach can use the roster to bark orders to the students, yet the roster itself doesn't hold the students on it, lol.

dado1996
26 Mar 2016, 04:48
Thanks. Now, is it possible to show the message "you can see x" any time I want? And not just when I enter a room?

HegemonKhan
26 Mar 2016, 05:29
anything you want to do 'on demand', means using Commands, as Commands take (activate via) typed-in user input (ie "on demand").

but you got to know how/what scripts to setup for doing what you want (I don't have the time at the moment)