Author Topic: TUTORIAL: Getting Player Input during Gamplay  (Read 85 times)

Offline manikus

  • Skriptor
  • Administrator
  • Hero Member
  • *****
  • Posts: 9634
TUTORIAL: Getting Player Input during Gamplay
« on: May 22, 2017, 04:04:19 PM »

Dungeon Craft designers have complete control over what the players see, hear and read in game during play. The player's only real control is over the name of the characters in the party (if the designer allows them that much). WOuldn't it be nice if the designer could allow the player to input and personalize their game? They can and this tutorial will show you how.
This tutorial is for designer's only.

Dungeon Craft editor*
text editor
*in the full DC download, this file is in the editor folder

Talk.txt   (created in your text editor)
Talk.bin   (compiled version of Talk.txt that the DC engine uses)

Part I:      GPDL **SHAZAM**
Thee have been a couple of demos on this topic over the years, but no tutorial. While tis may seem like a new feature, I assure this has been around for more than a decade and a half.
To get player input in your design, you need to do a few simple things.
1)   Open your design in the DC editor.
2)   In the cell where you want to get the player's input, add a Text Statement event.
3)   In the text box of your event enter "**SHAZAM**xyz()"
      **SHAZAM** is the keyword that the engine is looking for to access the talk.bin file (see below)
      xyz() is the name of a function in the talk.bin file (see below)
4)   Save your work.

It's that easy to place it in your design.

Part II:         Talk.txt
This part is the hardest part by far, but that doesn't mean that it's hard, likely, it's just confusing because you haven't done this type of thing before (speaking from personal experience).
We are going to create a text file with your function in it.
1)   Open your text editor and create a new file. Save it in your design folder ast "Talk.txt"
2)   Before we create your function, we need to create several simple functions that manage Talk.bin environment. The good news is that you need to create these once, and then you can copy and paste them into the Talk.txt files you make in your other designs.
   a)   The first function is called "error". It's used to set what we are going to be considered "True" in the Talk.bin environment. It's pretty basic.
   You need to declare a function called "error"
Code: [Select]
$FUNC error ()
   Then you add your script, in this case telling the engine what an error is. The script is in enclosed in brackets.
Code: [Select]
$IF (1){$RETURN true;}
$ELSE {$RETURN false;};
   And with the close bracket, you end the function.
Code: [Select]
} error;
   b)   The second function that you need is called "huh" and is used to give the talk.bin's response if the player fails to type anything or types something that odes not match any of the various terms that are used as keywords.
   Declare the funciton just like before.
Code: [Select]
$FUNC huh ()
   Add your script which will control the response with a $SWITCH so that the response is varied.
Code: [Select]
    $IF ($RANDOM(10) ==# 0) { // Provide hint for beginners!
        $SAY ("You should ask people their name and what they do.  "
              "And when you finish talking, you must say 'Bye'.");
    $SWITCH ($RANDOM(8)) {
    $CASE 0: $SAY ("I'm sorry.  I didn't understand you."); $BREAK;
    $CASE 1: $SAY ("Pardon me.  Can you say that again?");  $BREAK;
    $CASE 2: $SAY ("Excuse me?  I must not have been listening."); $BREAK;
    $CASE 3: $SAY ("Huh?"); $BREAK;
    $CASE 4: $SAY ("Speak up, please.  I'm a bit hard of hearing."); $BREAK;
    $CASE 5: $SAY ("You're mumbling.  Diction training might help."); $BREAK;
    $CASE 6: $SAY ("That's easy for you to say."); $BREAK;
    $CASE 7: $SAY ("That doesn't mean anything to me."); $RETURN "1";
   Now close the function.
Code: [Select]
} huh;
   c)   The third functoin that you need is called "listen" and is used to control parts of conversation used by all conversations.
   Declare your function, and this time a variable that operates in the function.
Code: [Select]
$FUNC listen(listenersName)
   You want to now add the script that does the heavy lifting for talk.bin. You should note in the script below that if the player types "name", "hello", "hi", "goodbye" or "bye", the script will react by giving a specific answer or by exiting talk.bin feature.
Code: [Select]
    $WHILE ($LISTEN()) {
        $SWITCH ($LISTENTEXT()) {
        $GCASE "name":
            $IF (listenersName == "") {
                $RETURN "1";
            $SAY("My name is " + listenersName + ".");
        $GCASE "hello|\\bhi\\b": 
            $SWITCH($RANDOM(4)) {
                $CASE 0: $SAY("Hello");     $BREAK;
                $CASE 1: $SAY("Hi"); $BREAK;
                $CASE 2: $SAY("Greetings"); $BREAK;
$CASE 3: $SAY("Well met."); $BREAK;
            } $ENDSWITCH;
        $GCASE "goodbye|bye":$SAY("Goodbye"); $RETURN "";
        } $ENDSWITCH;
        $RETURN "1";
    $RETURN "";
   Now we want to close the function.
Code: [Select]
} listen;
   Public Functions
   These are the functions that are called by **SHAZAM** in the Text Statement events.
   d)   Let's say for purposes of your design, you want to know which day of the week is the player character's favorite day.
   Start by declaring the function. Note that this is a public function.
Code: [Select]
$PUBLIC $FUNC FavoriteDay()
   In our script, we want to first check to see if we have already asked this PC what it's favorite day is, and if we haven't to ask it.
Code: [Select]
$IF ($GET_CHARACTER_SA($Myself(),"charFavDay") != "-?-?-"){$RETURN;}
$SAY ("Please enter your favorite day of the week.");
$WHILE ($NOT ($LISTEN())){$SAY ("I insist on knowing!");};
$SAY("Thank you.");
   Note that I chose to not cmpare the answer against the days of the week, but you can if you want to. I wanted to leave the answer open for things like "Humpday". The answer the player gives is stored in a Special Ability called 'charFavDay'.
   Just like with the earlier functions, we need to close this public function.
Code: [Select]
} FavoriteDay;
   In order to use this script in a Text Statement event, you would type:
Code: [Select]
**SHAZAM** FavoriteDay()
   in your event. You can use this same script in as many events as you would like.
   e)   Finally, let us add the public function that will facilitate a short conversateion with a character named Mary.
   First declare you public function. Note that I have included an example note like ones I use to keep the scripts in my talk.txt straight.
Code: [Select]
$PUBLIC $FUNC Mary() { // 1,6 portrait_NPC_ElfFemale2.png
   Enter your script now. Note the use of conditional statments - mary will only say the wrench is found if a paritcular ASL is found.
Code: [Select]
    $SAY("Well met. May I be of assistance to you?");
    $WHILE (listen("")) {
        $RESPOND ("name",   "I'm called Mary. What is your name?");
        $RESPOND ("job|occup", "I'm an attorney.");
        $RESPOND ("weather", "I'm sorry, due to client attorney confidentiality "
"I'm not allowed to discuss the weather.");
        $RESPOND ("Dungeon.Craft|DC", "Dungeon Craft? No comment.");
$IF ($GET_PARTY_ASL("LostWrench"))
$IF ($GREP("wrench.",$LISTENTEXT()))
$SAY ("Joe told me that he found his lucky wrench.");
$IF ($GREP("wrench",$LISTENTEXT()))
$SAY ("My brother lost his. That would be Joe, not Dave.");
//=====Other People=====
        $RESPOND ("Joe",   "He's very good with pipes if nothing else. Oh "
"and he is my brother.");
        $RESPOND ("Karl",   "Due to ongoing litigation, I can't discuss Karl.");
        $RESPOND ("Louis",   "Louis is an upstanding member of this community.");
        $RESPOND ("Mac",   "Mac is a sweetheart. Off the record? He's a big "
"old teddy bear.");
        $RESPOND ("Dave",   "Dave is my oldest brother. He runs the newstand "
"in the southeast corner of town.");
        $RESPOND ("Sharon",   "Oh dear, her apricot danishes are the best "
"I've ever had.");
        $RESPOND ("Diane",   "That's one strong woman. I'm proud to call her "
"my friend.");
        $RESPOND ("Lucy",   "She's a very important woman. If you don't believe "
"me, just ask her.");
        $RESPOND ("Jenny",   "I adore her. Jenny is the sister I always wanted, "
"and if Joe ever gets his act together, we will be sisters.");
//=====Specific to this person=====
        $RESPOND ("litigati", "Litigation is a nice way of saying someone has "
"been sued.");
        $RESPOND ("justice", "Justice is blind. And sometimes, deaf and dumb "
"as well.");
        $RESPOND ("attorney", "That would be lawyer to you, unless you're "
"from across the pond, then it would be barrister to you.");
        $IF(huh()) {$BREAK;};
   As with the other functions, the last thing to ddo is to close the function.
Code: [Select]
} Mary;
Part III:         Compiling and placing talk.bin
the final part of the tutorial deals with  compiling the talk.bin and placing it for DC to use.
To compile your file, you need to place your talk.txt file in the same direcotry as CPDLcomp4_5.exe. To compile you need to do one of the following:
   Command Line - type the following
Code: [Select]
GPDLcomp4_6.exe talk.txt talk.bin
   make a batch file that reads
Code: [Select]
GPDLcomp4_6.exe talk.txt talk.bin
   Create a shortcut, change the properties to read for executable (non including paty)
Code: [Select]
GPDLcomp4_6.exe talk.txt talk.bin
Once you have compiled your talk.bin file, place it in the design's Data folder. If everything has gone according plan, the next time you run your design the SHAZAM functions will run.

$SWITCH keyword
$WHILE keyword
$IF keyword
$RESPOND keyword
$BREAK keyword
$CONTINUE keyword
GPEL Functions
GPDL Nested Functions
GPDL Function Calls

« Last Edit: May 24, 2017, 12:17:35 PM by manikus »

Offline SilentThief

  • Dungeon Craft Tester
  • Hero Member
  • ***
  • Posts: 889
Re: Getting Player Input during Gamplay
« Reply #1 on: May 22, 2017, 10:45:40 PM »
Thank you for sharing this. Now I have yet another thing to try...


Offline Milos Gulan

  • Hero Member
  • *****
  • Posts: 3061
Re: Getting Player Input during Gamplay
« Reply #2 on: May 23, 2017, 04:10:31 AM »
Thank You, I will try doing this. Need to learn it first :)