Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I was able to get this work! 

As an exercise in trying to learn Decker, I tried to turn this system into a contraption. I got it to work in the Prototype editor, but as soon as I drop the contraption into a card, it seems to fall apart.

Any idea what I'm doing wrong?

%%WGT0{"w":[{"name":"Grid Map1","type":"contraption","size":[172,161],"pos":[170,91],"def":"Grid Map","widgets":{"0,0":{},"1,0":{},"2,0":{},"0,1":{},"1,1":{},"2,1":{},"0,2":{},"1,2":{},"2,2":{},"location":{"value":"2,1"},"player":{}}}],"d":{"Grid Map":{"name":"Grid Map","size":[172,161],"margin":[0,0,0,0],"description":"Selectable grid map. Clicking a box will navigate the player there and show available locations","image":"%%IMG2AKwAoQD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AnwFBAGoBQwBpAUQAaQFDAGwBBAAbAQQAGQEEAGwBBAAbAQQAGQEEAGwBBAAbAQQAGQEEAGwBBAAbAQQAGQEEAGwBBAAbAQQAGQEEAGwBBAAbAQUAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBAAcAQQAGAEEAGwBBQAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BBAAbAQQAGAEEAG0BPwBtAT8AbQE/AG0BPwBtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQQAGwEEABgBBABtAQUAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAQQAGgEEABgBBABuAT4AbgE+AG4BPgBvATwA/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8AhQ==","attributes":{"name":[],"label":[],"type":[]},"widgets":{"0,0":{"type":"button","size":[19,20],"pos":[16,16],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend","show":"none"},"1,0":{"type":"button","size":[19,20],"pos":[49,16],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend"},"2,0":{"type":"button","size":[19,20],"pos":[79,16],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend","show":"none"},"0,1":{"type":"button","size":[19,20],"pos":[16,50],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend"},"1,1":{"type":"button","size":[19,20],"pos":[49,50],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend","show":"none"},"2,1":{"type":"button","size":[19,20],"pos":[79,50],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend"},"0,2":{"type":"button","size":[19,20],"pos":[16,82],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend","show":"none"},"1,2":{"type":"button","size":[19,20],"pos":[49,82],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend"},"2,2":{"type":"button","size":[19,20],"pos":[79,82],"script":"on click do\n location.text:me.name\n player.pos:me.pos\n loc:0+\",\" split location.text\n neighbors:(list \"%i,%i\")format flip loc+(list -1,1,0,0),(list 0,0,-1,1)\n each name in (list \"%i,%i\")format 3 cross 3\n  card.widgets[name].toggle[\"solid\" name in neighbors]\n end\nend","show":"none"},"location":{"type":"field","size":[100,20],"pos":[64,128],"border":0,"value":"1,1"},"player":{"type":"canvas","size":[15,13],"pos":[49,50],"locked":1,"script":"on click pos do\n \nend\n\non drag pos do\n \nend\n\non release pos do\n \nend","border":0,"image":"%%IMG2AA8ADQASKAgABigKAAUoCwAEKAsABCgLAAQoCwAEKAsABCgLAAQoCwAFKAoABygHABI=","scale":1}}}}}

The problem is "card.widgets", I'm afraid.

A Card interface has a .widgets attribute, and a Prototype interface has a .widgets attribute, but a Contraption interface does not. While it is occasionally desirable to iterate over the widgets of a contraption instance (as in this case) from the inside, it is somewhat undesirable to expose the same information to code outside the contraption, since it would violate the principle of encapsulation.

Making something along these lines work in a contraption would require a somewhat different approach. Perhaps instead of a grid of buttons you could use a single Canvas widget, capture "click[]" events sent to it, and turn the neighbor-checking logic we used previously "inside-out". It would be a bit more code, but the advantage would be that you could design the system to work for a configurable, arbitrary-sized grid.