{"id":242,"date":"2012-06-17T13:21:35","date_gmt":"2012-06-17T11:21:35","guid":{"rendered":"https:\/\/herr-rau.de\/blogs\/inform\/?page_id=242"},"modified":"2012-06-17T13:21:35","modified_gmt":"2012-06-17T11:21:35","slug":"beschreibungen-von-objekten-variieren","status":"publish","type":"page","link":"https:\/\/herr-rau.de\/blogs\/inform\/?page_id=242","title":{"rendered":"Beschreibungen von Objekten variieren"},"content":{"rendered":"<p>Die Beschreibung eines Objekts wird durch das Attribut <code>description<\/code> festgelegt, das vom Typ <code>text<\/code> ist, also quasi ein String. Wenn man als Spieler ein Objekt untersucht oder betrachtet, wird standardm\u00e4\u00dfig die Beschreibung als Antwort ausgegeben. Manchmal m\u00f6chte man diese Beschreibung ganz oder teilweise variieren.<\/p>\n<hr\/>\n<h3>Beschreibung abh\u00e4ngig von einem Zustand<\/h3>\n<p>Dazu baut man Bl\u00f6cke mit <code>[if (Bedingung)], [otherwise if (Bedingung)], [otherwise], [end if]<\/code> in den Text ein.<\/p>\n<p>In diesem Beispiel wird zuerst der Spieler mit den booleschen Attributen &#8220;hungrig&#8221; und &#8220;durstig&#8221; versehen, und die Beschreibung des Spielers angepasst an diese Werte. Um das testen zu k\u00f6nnen, muss man noch etwas zu essen und zu trinken bereitstellen und Regeln f\u00fcr die \u00c4nderung des Zustands angeben:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">\r\n&quot;Hungry and thirsty&quot; by Thomas Rau\r\n\r\nThe World is a room.\r\nA person can be thirsty.\r\nA person can be hungry.\r\nThe player is hungry and thirsty.\r\n\r\nThe apple and the lemonade are edible things in the World.\r\n\r\nAfter eating the apple:\r\n\tnow the player is not hungry;\r\n\tsay &quot;You eat the apple. Not bad.&quot; \r\nAfter eating the lemonade:\r\n\tnow the player is not thirsty;\r\n\tsay &quot;You drink the lemonade. Not bad.&quot; \r\n\r\nInstead of drinking something (called the drink), try eating the drink.\r\n\r\nThe description of the player is &quot;You look &#x5B;if the player is hungry and the player is thirsty]hungry and thirsty&#x5B;otherwise if the player is hungry]hungry&#x5B;otherwise if the player is thirsty]thirsty&#x5B;otherwise]well fed and full of energy&#x5B;end if].&quot;\r\n\r\nTest me with &quot;x self \/ eat apple \/ x self \/ drink lemonade \/ x self&quot;\r\n<\/pre>\n<p>In Java s\u00e4he das ganze so aus:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic String getDescription() {\r\n\tString answer = &quot;You look &quot;;\r\n\tif (isHungry &amp;&amp; isThirsty) {\r\n\t\tanswer = answer+&quot;hungry and thirsty&quot;;\r\n\telse if (isHungry) {\r\n\t\tanswer = answer+&quot;hungry&quot;;\r\n\t}\r\n\telse if (isThirsty) {\r\n\t\tanswer = answer+&quot;thirsty&quot;;\r\n\t}\r\n\telse {\r\n\t\tanswer = answer+&quot;well fed and full of energy&quot;;\r\n\t}\r\n\tanswer = answer + &quot;.&quot;;\r\n\treturn answer;\r\n}\r\n<\/pre>\n<p>Eckige Klammern in einem Textstring bedeuten immer, dass hier Code ausgef\u00fchrt wird. Das sind entweder Kontrollstrukturen wie oben, oder die Bezeichner von Variablen, Objekten oder Methoden. <\/p>\n<p>Alternativ zur L\u00f6sung oben k\u00f6nnte man eine say-Methode definieren und aufrufen. So eine Methode bietet sich wie immer dann an, wenn der Codeblock eventuell mehrfach verwendet wird:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">\r\nThe description of the player is &quot;You look &#x5B;description of your state].&quot;\r\n\r\nTo say description of your state:\r\n\tif the player is hungry and the player is thirsty:\r\n\t\tsay &quot;hungry and thirsty&quot;;\r\n\totherwise if the player is hungry:\r\n\t\tsay &quot;hungry&quot;;\r\n\totherwise if the player is thirsty:\r\n\t\tsay &quot;thirsty&quot;;\r\n\totherwise:\r\n\t\tsay &quot;well fed and full of energy&quot;.\r\n<\/pre>\n<hr\/>\n<h3>Wechselnde Beschreibung<\/h3>\n<p>Oder man legt eine Reihe verschiedener Varianten fest, die in zuf\u00e4lliger oder nicht zuf\u00e4lliger Weise ausgew\u00e4hlt werden. Das geschieht, in dem man an eine Stelle in der Beschreibung <code>[one of]<\/code> gefolgt von mehreren durch <code>[or]<\/code> getrennten Alternativen setzt:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">\r\n&quot;Magic 8-Ball&quot; by Thomas Rau\r\n\r\nThe World is a room.\r\n\r\nThe Magic 8-Ball is a thing in the World. The description is &quot;It looks like a big black pool ball. Through a little window, you can see the message: '&#x5B;one of]It is certain&#x5B;or]It is decidedly so&#x5B;or]Without a doubt&#x5B;or]Yes \u2013 definitely&#x5B;or]You may rely on it&#x5B;or]As I see it, yes&#x5B;or]Most likely&#x5B;or]Outlook good&#x5B;or]Yes&#x5B;or]Signs point to yes&#x5B;or]Reply hazy, try again&#x5B;or]Ask again later&#x5B;or]Better not tell you now&#x5B;or]Cannot predict now&#x5B;or]Concentrate and ask again&#x5B;or]Don't count on it&#x5B;or]My reply is no&#x5B;or]My sources say no&#x5B;or]Outlook not so good&#x5B;or]Very doubtful &#x5B;purely at random].'&quot;\r\n\r\nUnderstand &quot;ball&quot; as the 8-Ball.\r\n\r\nTest me with &quot;x ball \/ again \/ again&quot;\r\n<\/pre>\n<p>Abgeschlossen wird diese Reihe dann entweder mit <\/p>\n<ul>\n<li><code>[purely at random]<\/code><br \/>\n(zuf\u00e4llige Auswahl)<\/li>\n<li><code>[at random]<\/code><br \/>\n(zuf\u00e4llige Auswahl, aber niemals zweimal hintereinander das gleiche)<\/li>\n<li><code>[then purely random]<\/code><br \/>\n(erst mal in genau der angegebenen Reihenfolge, bis alle mal dran waren, und danach kommt immer ein zuf\u00e4lliges Element)<\/li>\n<li><code>[then at random]<\/code><br \/>\n(erst mal in genau der angegebenen Reihenfolge, danach zuf\u00e4llig, aber nie zweimal hintereinander das gleiche)<\/li>\n<li><code>[sticky random]<\/code><br \/>\n(eines zuf\u00e4llig, aber dann jedesmal dasselbe)<\/li>\n<li><code>[as decreasingly likely outcomes]<\/code><br \/>\n(zuf\u00e4llig, aber mit sinkender Wahrscheinlichkeit &#8211; das letzte von n Elementen ist n-mal unwahrscheinlicher als das erste)<\/li>\n<li><code>[cycling]<\/code><br \/>\n(zyklisch der Reihe nach, angefangen beim ersten)<\/li>\n<li><code>[in random order]<\/code><br \/>\n(in zuf\u00e4lliger Reihenfolge solange, bis jedes mal dran war, und dann in neuer zuf\u00e4lliger Reihenfolge wiederholt)<\/li>\n<li><code>[stopping]<\/code><br \/>\n(der Reihe nach alle bis zur letzten Alternative, und danach immer nur diese)<\/li>\n<\/ul>\n<hr\/>\n<p>Das alles gilt nat\u00fcrlich nicht nur f\u00fcr das Beschreibungs-Attribut, sondern f\u00fcr jeden beliebigen String.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Die Beschreibung eines Objekts wird durch das Attribut description festgelegt, das vom Typ text ist, also quasi ein String. Wenn man als Spieler ein Objekt untersucht oder betrachtet, wird standardm\u00e4\u00dfig die Beschreibung als Antwort ausgegeben. Manchmal m\u00f6chte man diese Beschreibung &hellip; <a href=\"https:\/\/herr-rau.de\/blogs\/inform\/?page_id=242\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":145,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-242","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages\/242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=242"}],"version-history":[{"count":0,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages\/242\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages\/145"}],"wp:attachment":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}