With the "Make Magnet" contraption in the "All About Draggables" deck, I'd like to make the draggable canvases made with it spawn with a script. How can I do this?
Hi! This isn't an answer yet, just some clarifying questions:
Are you working on using the "Make Magnet" example to make magnets that are created with scripts in them that use things like rect.overlaps and rect.constrain from the same example deck?
And did you want to make it so that only some of them do something when they're overlapping, and others don't? (based on some condition, or your mention of a whitelist).
Actually if you could give a specific description of what you're trying to do then I think we could help make sure you have all of the pieces of it that you need.
Yes, the example contraption, and I more specifically want to apply a general script to all of the canvases made with it to make them work with the Overlaps mechanic. It's the mechanic with a script applied to a draggable canvas -
on release do
if rect.overlaps[me target]
alert["You hit the target!"]
end
end
It would then execute an action if placed on the specifically named widget.
To make a project as a beginner, I'd just like to collate different contraptions to make games and potentially study the code and provided documentation.
The script on the “Make Magnet” button just creates a new Canvas widget and adds it to the card. You can set or retrieve the script of a widget with the .script attribute. So:
mycanvas.script:"on click do alert[\"boo\"] end"
Alternatively, when a widget doesn’t have a handler for a particular event, that event bubbles up to the card, then the deck. If you want a bunch of widgets that all have the same behaviour, you can put the on click ... end handler in the card, and not have to worry about adding it to each widget individually.
A deck contains cards, cards contain widgets.
When you click a button in the “interact” mode, or a script runs somebutton.event["click"], Decker looks inside the button’s script for an on click do ... handler.
If it can’t find one, the event “bubbles up” to the card, and Decker looks for an on click do ... handler there.
If it can’t find one, the event “bubbles up” to the deck, and Decker looks for an on click do ... handler there.
If it can’t find one, Decker has built-in default handlers for certain events (like dragging on a canvas to draw on it), but most events wind up being ignored.