Deploying DeadLetter Learn DeadCL DeadCL Tutorials Trusted Domains Publishers

Walk throughs

Author Keys Conversations Libraries Arrays

Network Status Community Hub Contact Us



Hangman
(game)

View tutorials overview

Introduction

While the game Hangman may not interest you the principles we'll use could be applied to an assortment of other applications.

The Library & Conversation used are linked below, for both comparison and ease of execution.


Everything shown in blue must be substituted with your own values.

This tutorial will not deal with the initial establishment of DeadLetter or your web server/web presence.

What you'll learn

- How to use object substitutions
- How to create and use Linear Graphics
- How to post fixed object values

What you'll need

- A Web Server: DeadLetter requires a web server of some description, you'll need access to add and modify files
- Sub domain: you'll need a domain (or sub-domain) generally we suggest using dld.yourdomain.com however the choice is yours, just emsure if matches your Author Key
- Author Key: it goes without saying you'll need an Author Key

Step One - Linear Graphic

Their are multiply ways to create a 'hanged man' but for this example we'll use a Linear Graphic. In deadCL we use Linear Graphics as a simple method to 'draw' text based images with pre-defined object values.

The Linear Graphic shown below is what we'll be using to create our 'hanged-man'.


#00 #01 ______ #02 | | #03 | O #04 | /|\ #05 | | #06 | / \ #07 | #08 +++++++++++ #09 +++++++++++ #10 #11 #12 ----------------------------- #13 | | #14 #15 1 2 3 4 5 6 7 8 9 #16 #17 | | #18 ----------------------------- #19 #20 #21 #22 | #23 | #24 | #25 | #26 | #27 | #28 +++++++++++ #29 +++++++++++ #30 #31 #32 ----------------------------- #33 | | #34 #35 1 2 3 4 5 6 7 8 9 #36 #37 | | #38 ----------------------------- #39 #40 * * * * * * * * *

Understanding Linear Graphic numbering

While deadCL is designed to output basic UTF-8 text, their are occasions when handling (direct) graphical outputs are advantageous.

That said outputting models is complicated, each line requires a number & it's good practice to ensure they're all the same number of characters beginning with '#' preferably starting with 0 (like most computers deadCL starts from zero).

#00 #01 #02 #04 #05

Using Linear Graphic modelling

For our purposes we need to replace one line with another, for this to be possible both lines must present within the same file (you could you two different files but this increases the possibility of their being a line conflict).

Replacing lines 01 to 06 with lines 21 to 26 is simple. By creating two sets of completing object data (as shown) we can instruct deadCL to reload the entire line thus changing the output 'image' with the only noticeable change to the user show in orange. We'll go through how to change the Linear Graphic later in this tutorial.

#00 #01 ______ #02 | | #03 | O #04 | /|\ #05 | | #06 | / \ #07 | #08 +++++++++++ #09 +++++++++++ #20 #21 #22 | #23 | #24 | #25 | #26 | #27 | #28 +++++++++++ #29 +++++++++++

Step Two - Defining Linear Graphic sections

Okay, now it's time to build the Library. The first thing we'll do is start 'drawing' the layout we'll update with each incorrect guess.

To begin we need to load our Linear Graphic & define the sections we want to change.

            

HANGMAN; @ID_HANGMAN.TXT { DRAW-STAGES; #00, #01, #02, #03, #04, #05, #06, #07 DRAW-NORMAL; #20, #21, #22, #23, #24, #25, #26, #27 } LAYOUT; @ID_HANGMAN.TXT {#20, #21, #22, #23, #24, #25, #26, #27, #28, #29, #30, #31, #32, #33, #34, #35, #36, #37, #38, #39} HANGED; DRAW-STAGES -- SMALLEST TO LARGEST, [bnd _VAL #00 -- #07]

The hanged-man

In the first KC we'll define is the 'hanged-man'. It's best to do this in two steps by listing a 'normal' & 'changed state'.

We've used 'DRAW-STAGES' & 'DRAW-NORMAL'

'DRAW-STAGES' is the steps shown above in orange, while 'DRAW-NORMAL' are the lines without the hanged-man.

            

HANGMAN; @ID_HANGMAN.TXT { DRAW-STAGES; #00, #01, #02, #03, #04, #05, #06, #07 DRAW-NORMAL; #20, #21, #22, #23, #24, #25, #26, #27 }

The layout

The layout is perhaps the easiest section to define, all that's required is a statement listing each line & a link to the Linear Graphic.

            

LAYOUT; @ID_HANGMAN.TXT {#20, #21, #22, #23, #24, #25, #26, #27, #28, #29, #30, #31, #32, #33, #34, #35, #36, #37, #38, #39}

Setting the draw order

It's all very well creating drawing stages but without instructions to handle drawing your Linear Graphic nothing will happen.

Here we'll tell deadCL to draw the smallest to largest number by binding the value of 00 to 07 in the order 00, 01, 02, 03, 04, 05, 06, 07, to the KC 'HANGED' by binding bnd the values in this order.

            

HANGED; DRAW-STAGES -- SMALLEST TO LARGEST, [bnd _VAL #00 -- #07]

Step Three - handling words

Now things get interesting, for the game Hangman we need three things

1. to choose a word, long enough for the man to hang but not too long otherwise it won't fit in the space allowed.
2. To store the word as individual letters, if we skipped this step the Conversation would require (whole) words rather than letters
3. logic for both a match & no match


            

WORDS; LIST, ALL -- @ID_ DAW_2019 AS '$_WRD*' {DRP _all -- .LTO '8' LETTERS, DRP _all -- .GTO '8' LETTERS SELECT 0, SET AS $_RAMDOM} MATCH; $_RAMDOM -- ?divide _ALL .GTO '0' RECORD, LETTERS singularly { SET _VAL AS; 1, 2, 3, 4, 5, 6, 7, 8, 9 on #35 as 'THE_WORD' } SET; $_RAMDOM as 'MATCH' NO-MATCH; DRAW, LAYOUT -- HANGED {.OVRIDE, CONFLICT; #20, #21, #22, #23, #24, #25, #26, #27, #28} ON-MATCH; CHANGE #35 TO ?MATCH

Selecting our word

Luckily deadCL has an offical library listing (almost) every word, as a result it's very easy to create a list of every (english) word with one command LIST, ALL -- @ID_ DAW_2019 AS '$_RAMDOM*'

The list is then thinned down by removing every word with less than 9 'letters' DRP _all -- .LTO '8' LETTERS

and every word with more than 9 'letters' DRP _all -- .GTO '8' LETTERS

This leaves a list of just those words comprised of 9 letters or characters. So our next command needs to select a word at random from this list. SELECT 0, SET AS $_RAMDOM

            

WORDS; LIST, ALL -- @ID_ DAW_2019 AS '$_WRD*' {DRP _all -- .LTO '8' LETTERS, DRP _all -- .GTO '8' LETTERS SELECT 0, SET AS $_RAMDOM}

Dividing our word

Okay so now we've got a word with a variable value ($_ramdom) but we still need to transform it into individual letters.

We can do this by dividing the object value into values no greater than 1 (0) $_RAMDOM -- ?divide _ALL .GTO '0' before recording the values singularly. RECORD, LETTERS singularly

Now we've got our 'new' value(s) we need to save them against the numbers displayed on line #35 SET _VAL AS; 1, 2, 3, 4, 5, 6, 7, 8, 9 on #35

            

MATCH; $_RAMDOM -- ?divide _ALL .GTO '0' RECORD, LETTERS singularly { SET _VAL AS; 1, 2, 3, 4, 5, 6, 7, 8, 9 on #35 as 'THE_WORD' }

Setting match actions

It goes without saying that we'll need to give $_ramdom a fixed value to allow the Conversation & Library to use the same information set. This is easily done; $_RAMDOM as 'MATCH'

While we'll use the Conversation to launch a match it's important to create the logic used to do this we'll give the KC 'NO-MATCH' a value in this case DRAW, LAYOUT -- HANGED this tells deadCL to 'draw the layout with hanged-man.

Now we've got our new value(s) we need to save them against the numbers displayed on line #35 SET _VAL AS; 1, 2, 3, 4, 5, 6, 7, 8, 9 on #35

We don't need to worry about the draw order as deadCL has already been told to 'show' each number as a letter.

Provided it matches 'THE_WORD'

            

SET; $_RAMDOM as 'MATCH' NO-MATCH; DRAW, LAYOUT -- HANGED {.OVRIDE, CONFLICT; #20, #21, #22, #23, #24, #25, #26, #27, #28} ON-MATCH; CHANGE #35 TO ?MATCH FROM 'THE_WORD'

Step Four - The Conversation

Lets move onto the boring bits (well the Conversation file). It's incredibly simple because it's only handling three things.

1. the input address, this is how deadCL knows what your 'guesses' are
2. the Key Commands required to start a 'no-match' or 'match'
3. a post request, we need this otherwise nothing will happen


            

dld.keyset('NAME_YOURNAME') *Catch-all - libs *input, @my_guess.txt MATCH; INPUT, COMPARE 'THE_WORD' ELSE; INPUT = NO MATCH POST; [ON-MATCH] on MATCH, ELSE [NO-MATCH] *END*

Adding Libraries

If you don't want to use a custom Linear Graphic then the best option (or the very least, safest for testing) is to use the Offical DeadLetter Libraries by adding them all.

  
 

  *Catch-all - libs



Setting your input

It goes without saying but you'll need to set an input address (if you don't know what an input address does read this)

This can be anything just remember the '@' is your domain name (URL).

  
 

  *input,
        @my_guess.txt



Handling inputs & comparing

Thanks to all the heavy lifting being performed by the Library our Conversation just needs to 'compare' the input (that being a single letter) to the letters (objects) in 'THE_WORD'

In the next KC we set the meaning of the OBJECT (word) 'ELSE' to essentially mean the opposite of 'MATCH'.

      
 


  MATCH;
        INPUT, COMPARE 'THE_WORD'
  
  ELSE;
	INPUT = NO MATCH
	


Making the Post request

Remember the two KC's in our Library?

ON-MATCH & NO-MATCH

Well this is where they come in to our Conversation, our post request is simply asking for deadCL to run one or the other.

 

POST; [ON-MATCH] on MATCH, ELSE [NO-MATCH]


You're Done!

By now you should have a (very) basic understanding of using Linear Graphics with DeadLetter (deadCL)


NOTE: This is not intended as a production ready Conversation, simply an example of deadCL.

This code expects that you will simply add each new letter rather than replacing the value every time, i.e "abc" rather than "a" "b" "c" to change this logic you'll need to insert


Adding a HOLD_STATE

it goes without saying you'll need to host this Key Command yourself, either within it's own library (not recommended) or by copying & insert it into our Offical Library.

This will force deadCL to hold the value(s) till you forcefully restart the Conversation using a "^FLUSH" command.
 

@my_guess.txt; HOLD_STATE -- _VAL _all