{"id":76,"date":"2014-04-05T17:39:23","date_gmt":"2014-04-05T17:39:23","guid":{"rendered":"https:\/\/blogs.scummvm.org\/josejx\/?p=76"},"modified":"2022-05-21T17:41:48","modified_gmt":"2022-05-21T17:41:48","slug":"mystery-of-the-non-vanishing-pretzel","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/josejx\/2014\/04\/05\/mystery-of-the-non-vanishing-pretzel\/","title":{"rendered":"Mystery of the Non-Vanishing Pretzel"},"content":{"rendered":"<p>You know that feeling when you reach into a bowl of pretzels and munch down, enjoying that savory jerky flavor. Then, when you reach into the bowl again, you find that the old pretzel that you just ate is still stuck to your hand&#8230;<\/p>\n<figure id=\"attachment_78\" aria-describedby=\"caption-attachment-78\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/PretzelStillInHand.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-78\" src=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/PretzelStillInHand.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/PretzelStillInHand.png 640w, https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/PretzelStillInHand-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"caption-attachment-78\" class=\"wp-caption-text\">Mmm&#8230; Delicious Magical Jerky Pretzels, Once You Pop, You Can&#8217;t Stop<\/figcaption><\/figure>\n<p>Okay, so it&#8217;s another bug! Looking into the script <i>_props1.lua<\/i>, we see the following sequence is run when Guybrush eats the pretzel:<\/p>\n<ul>\n<li>The pretzel is detached from the bowl<\/li>\n<li>The pretzel is attached to Guybrush @ <i>wrist_l<\/i><\/li>\n<li>When the eating chore finishes, the pretzel has <i>set_wear_chore(nil)<\/i> run on it<\/li>\n<\/ul>\n<p>It looks like the call to <i>set_wear_chore(nil)<\/i> makes the actor invisible. Let&#8217;s try it out on the retail copy, using the debug window. Let&#8217;s see if we can make the drunk vanish:<\/p>\n<ul>\n<li><i>drunk:set_wear_chore(nil)<\/i><\/li>\n<\/ul>\n<figure id=\"attachment_79\" aria-describedby=\"caption-attachment-79\" style=\"width: 648px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/Vanished.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-79\" src=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/Vanished.png\" alt=\"\" width=\"648\" height=\"507\" srcset=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/Vanished.png 648w, https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/Vanished-300x235.png 300w\" sizes=\"auto, (max-width: 648px) 100vw, 648px\" \/><\/a><figcaption id=\"caption-attachment-79\" class=\"wp-caption-text\">Abracadabra! Where Did the Drunk Go?<\/figcaption><\/figure>\n<p>So what is ResidualVM doing wrong? Let&#8217;s examine the Lua for <i>set_wear_chore<\/i>, a method of <i>actor<\/i> in <i>_actors.lua<\/i>. There&#8217;s a lot going on here, so I reset the scene and then started stepping through each command in <i>set_wear_chore<\/i> using the retail version until the drunk vanished again. Luckily, it turns out that it&#8217;s first action, the call to <i>stop_all_chores,<\/i> that makes the actor vanish!<\/p>\n<p>This method is from the <i>actor<\/i> object as well, and the code for it is also in <i>_actors.lua<\/i>. Luckily, it&#8217;s just a simple call to the Lua function StopActorChores, which if we follow it through, simply calls the <i>stop() <\/i>method on every one of the actor&#8217;s chores. Before we get much further, let&#8217;s take a stop ourselves to review what Chores are.<\/p>\n<p>Chores are instructions that describe what the actor is supposed to look like, or what the actor is supposed to do. As an example, you can make the drunk look like Meathook by doing the following from the console:<\/p>\n<ul>\n<li>drunk:set_wear_chore(&#8220;meathook.cos&#8221;)<\/li>\n<\/ul>\n<figure id=\"attachment_80\" aria-describedby=\"caption-attachment-80\" style=\"width: 640px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/DrunkMeathook.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-80\" src=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/DrunkMeathook.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/DrunkMeathook.png 640w, https:\/\/blogs.scummvm.org\/josejx\/wp-content\/uploads\/sites\/23\/2014\/04\/DrunkMeathook-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><figcaption id=\"caption-attachment-80\" class=\"wp-caption-text\">The Drunk becomes Meathook!<\/figcaption><\/figure>\n<p>They usually also contain rules for behaviors, like when Guybrush eats a pretzel (to use a topical example):<\/p>\n<ul>\n<li>guybrush:play_chore(&#8220;eat_pretzel&#8221;)<\/li>\n<\/ul>\n<p>In the retail version, this runs the chore, but here, it doesn&#8217;t. This is probably another issue that needs to be looked into!<\/p>\n<p>So, what have we learned? When the method <i>set_wear_chore<\/i> is called with nil, the actor&#8217;s costume is stopped as well, which results in the actor not being drawn. In ResidualVM, the actor&#8217;s costume is stored in a separate place from other chores and isn&#8217;t stopped when <i>StopActorChores<\/i> is called. How do we fix this?<\/p>\n<p>I decided that it would be easiest to just store if the wearChore is active or not. I also added a check to see if the wearChore was active in the draw method in costume.cpp to prevent the object from being drawn if the wearChore is inactive. Finally, I added a method to allow setting and getting this state variable. This was pushed in <a href=\"https:\/\/github.com\/residualvm\/residualvm\/pull\/858\">PR #858.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You know that feeling when you reach into a bowl of pretzels and munch down, enjoying that savory jerky flavor. Then, when you reach into the bowl again, you find that the old pretzel that you just ate is still stuck to your hand&#8230; Okay, so it&#8217;s another bug! Looking into the script _props1.lua, we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":2,"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/posts\/76\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/josejx\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}