Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

One of the strengths of a contraption is that code running outside the contraption doesn’t know about what’s happening inside it. That means when you’re creating a contraption prototype you don’t have to keep in mind all the other thing going on in a deck, and when you’re working on the deck you don’t have to keep in mind the contents of every contraption. However, that does mean you need to take care when getting data into or out of a contraption.

In short, a script outside the contraption can’t refer to widgets inside it… at least, without permission.

Code outside the contraption can poke at all the attributes listed in the Contraption interface in the Decker documentation, but the contraption can add extra attributes of its own. If your prototype’s script has a handler like this:

on get_gimmefive do
 5
end

…then code outside the contraption can do somecontraption.gimmefive and get 5 as the result. In the same way, if your prototype script has a handler like:

on set_taketen val do
 if val = 10
  alert["Thanks!"]
 else
  alert["Not what I asked for."]
 end
end

…then code outside the contraption can do somecontraption.taketen:"hello" and it will produce an alert.

If your prototype has a get_foo handler with no set_foo, it’ll be read-only; if your prototype has a set_foo with no get_foo, it’ll be write only; if your prototype has both then it behaves like any other variable.

In your case, you probably want your prototype to have a handler like set_image that takes an image and stores it on an internal canvas somewhere (or perhaps a rich text field). Then in the deck outside instead of writing something like this:

# This doesn't work
somecontraption.widgets.storage.paste[mycanvas.copy[]]

…instead you can write something like this:

# This *can* be made to work
somecontraption.image:mycanvas.copy[]

…and inside the prototype:

on set_image val do
 if "image" = typeof val
  storage.paste[val]
 else
  show["Tried to store" val "but I need an image"]
 end
end

(the show[] just gives you a clue about what might have gone wrong if things don’t work as expected)

(+2)

I was able to get the first 2 examples working, but I'm having trouble with the last one.

(I'm assuming typeof is supposed to be a placeholder thing since I couldnt get it working, although admittedly I'm not positive on that since I'm still new to all this syntax stuff.)



As of right now, the box1 contraption is non-responsive as I haven't been able to get it to alert.
(+3)

"typeof" is a unary operator in Lil which tells you the name of the type of any value:

typeof "foof"      # "string"
typeof 123.4       # "number"
typeof (11,22,33)  # "list
(+1)

Beastmode, thank you for the clarification.

I admittedly am still having some trouble with the last example. I've copied and pasted the code at this point and renamed all of the assets to their placeholder names to miminize accidentally breaking something, but the contraption is still currently completely non-responsive to both the if and else statement, but was working initially with the previous examples.

(+2)

Copy this text to the clipboard, then in Decker you should be able to Edit → Paste Card:

%%CRD0{"c":{"name":"home","widgets":{"highlighter1":{"type":"contraption","size":[128,128],"pos":[224,112],"def":"highlighter","widgets":{"storage":{"image":"%%IMG3AEAAQAKEj6kW7Q/dmrTOiDO0vOsPdqICBlc5il+6plTmLnCMYPRr0/mNb7HPs+w8wCCnKEQak4+jcsmUVJ7QaKN3rf6ap6x2K01Qv07vYVwzjcxlNjeqChPD6LN8em/b2dg43wpQx/AGyCJBiPfXZ3iFuOintnaY1xU5Z3kpOKhYCeb4eOlJ2SnJiTUqg5pqWqkq5kqCWcoaS1Zoq6WJOyu7y6Pr29YbLEq8BGy8+pmcScusDPsciyytkTiso9q0vOksfB3oGvFbty0+1Gy6Ud4CPQ7eLVyCch2pOU8PlxYdjq+rxK3eO0Z/qNniZjAXwoTHAvbjp9DhQ29QBn4zZlEetooS3W0kx3BGFXSiIJ4yKbDjHpJG5rViOdIfPowyrbkoAA=="}}},"sendnum":{"type":"button","size":[96,16],"pos":[112,112],"script":"on click do\n highlighter1.highlighted:5\nend","text":"Send Number"},"happy":{"type":"button","size":[96,16],"pos":[112,144],"script":"on click do\nhighlighter1.highlighted:image[\"%%IMG3AEAAQAKEj6kW7Q/dmrTOiDO0vOsPdqICBlc5il+6plTmLnCMYPRr0/mNb7HPs+w8wCCnKEQak4+jcsmUVJ7QaKN3rf6ap6x2K01Qv07vYVwzjcxlNjeqChPD6LN8em/b2dg43wpQx/AGyCJBiPfXZ3iFuOintnaY1xU5Z3kpOKhYCeb4eOlJ2SnJiTUqg5pqWqkq5kqCWcoaS1Zoq6WJOyu7y6Pr29YbLEq8BGy8+pmcScusDPsciyytkTiso9q0vOksfB3oGvFbty0+1Gy6Ud4CPQ7eLVyCch2pOU8PlxYdjq+rxK3eO0Z/qNniZjAXwoTHAvbjp9DhQ29QBn4zZlEetooS3W0kx3BGFXSiIJ4yKbDjHpJG5rViOdIfPowyrbkoAA==\"]\nend","text":"Send Happy"},"sad":{"type":"button","size":[96,16],"pos":[112,176],"script":"on click do\nhighlighter1.highlighted:image[\"%%IMG3AEAAQAKEj6kW7Q/dmrTOiDO0vOsPdqICBlc5il+6plTmLnCMYPRr0/mNb7HPs+w8wCCnKEQak4+jcsmUVJ7QaKN3rf6ap6x2K01Qv07vYVwzjcxlNjeqChPD6LN8em/b2dg43wpQx/AGyCJBiPfXZ3iFuOintnaY1xU5Z3kpOKhYCeb4eOlJ2SnJiTUqg5pqWqkq5kqCWcoaS1Zoq6WJOyu7y6Pr29YbLAqlYfzJO/MboVOSnEn7+twsKr1XnTYUPbwKvQl8LNwdm51o8g1+jZ0eOEkLPA3b1N5+Tu7+bhrvTf72zc/bKXatkHFC9CTgiYHyBBLL9ychvlyoFFYZY+4hwXsTyWTs1/FiOHtLPnIMeUPhNpEWlxkkeQrWuHVW4rWgGAKkSZbUnj3smTNFAQ==\"]\nend","text":"Send Sad"}}},"d":{"highlighter":{"name":"highlighter","size":[128,128],"margin":[0,0,0,0],"description":"Draws attention to an image","script":"on get_highlighted do storage.copy[] end\non set_highlighted val do\n show[\"called set_image with\" val]\n if \"image\" = typeof val\n  storage.clear[]\n  storage.paste[val]\n else\n  alert[\"%J is not an image\" format val]\n end\nend","image":"%%IMG3AIAAgAUgII5kaZ5oqq5s675wLM90bd94DnCcfvK+oNDEAw6LvaHyl3whmypj6ymULkVIWJa1JUq7OvCSOhWjzLss2Yc+Fl3rVHxEbdvm3pudhGdaS097NXuCK32Ab2V/fIGLOYFniYOScpRRloiQSpqZjpl+UJGenaGkmGx9gnhdmoedXJybaKqxao09qVCFjV6lNKunpk23kLOSu7FpwTJzhVh1xFvGX8t0rbyPYs7P0drTRsjdlNWGYNvWxNbovtxJ4eKM5JfH8r1x0sv4o+3RppPQ+0R5A5cvkblQ3UAFhJUuBrZ17SoRpGblocI74tjNG+iu4MRhllxFZJaxnkKEBunF6/hRI0OXAkvqKQWQJcg3+mBu1GmvJE+SQHKurPmz569vC2f4HIpz259zQJMehcfUokRdJo9eWXcrpsiVXLeKrbqv4cubRcfO/MrPJCuoJNWOVHTurdSpaeXGi8rvClu9qJrCrQcXMMaWDr8WNow3GV07ixlHNfsY2F3J/5aevZcVc2aZlWt6Vkuvq5OMoz07htMvteu1q1/LPv13tu2eeW9L9plbt17evX2T5i1ceMLOxZMrx3F5+evIzhnXjhs9DPSN1Q9fx55dqVXW5ZB3b017VOzuJ6e3xaS+ekJloTmLNw78vDLy7X3XN72z6/bn+9mHG2XorXdcfvfxVyBT4H0moHsPBhahcwqK9d2C621FHoYDjrEhh8K4QSCIRgVRIYnziNgcihquyOKLMMaYnYsymjhfjdbdOCONiemY3Imy8EgfkCoGp9+IWrwXFopElhcgkz4KUx+JCHq1H4gX2ogah0i2+J9rSlpYpW5hBvnlbGVKGOWRgo2ZHo52TRjemsUd1CRrdP5IU5en4Zikm37+E6gsg0onJ2xCsnlofIvqyedkaR7ZX5aQfqhoTEPlWMyZYpaWIFZGMoEbLI0Fh1qjzCkGlaVz9kOpmeREuCWjZLxaZFkParYZJ6zeGsydn+ICbLDs2AJoq7m8ymubMCGZU54DmtHrp0vSEtQpcSbq1VwG/iofWhqJZg8pVdgJKpGWnYupY9JCm+Ar3XrriLlWpltiqhyFFds3YIES7LgA4zsvuG1VIhAiVxUM78La6VSrrf6WpzDCFzn4mIE9NldRYVVCzA1XyP2XX6Me15uWyIuNPCZREiPaGFCwQYRnqH29bChFRaGsI6oxq9Nyw0ADBqi27x52M9HZuCu00tphyGk2XDJdKHdTy4V01VjTEAI=","widgets":{"storage":{"type":"canvas","size":[64,64],"pos":[32,32],"locked":1,"border":0,"scale":1}}}}}

There’s a contraption with an embedded canvas, that draws a border around the image on the canvas to highlight it. The contraption has a .highlighted attribute which allows the canvas image to be set or retrieved. There’s also three buttons, one which sets the .highlighted attribute to a number (which should be rejected) and two which set it to an image (to demonstrate the image is actually being changed).

It’s basically the same as my last example, but I had to change the attribute name from .image to .highlighted. It turns out that contraptions already have a .image property (which refers to the background image of the contraption, like card.image refers to the background image of a card), so you can’t override that with your own set_image{} handler. I wrote my original example based on my experience of attributes in general, but I hadn’t actually tested it as written, sorry.

(+3)

You're all good. Thank you so much for the help! I was finally able to get it working! I'd share a photo of the final results of my testing but the placeholder artwork i am using is just one of those graffiti penises and Im to sleepy to make something more respectable right now.