JohnEarnest/Decker

Store widget references in a variable?

gcanyon opened this issue · 3 comments

If I do something like

on click do
x:"fish"
x.text:x.text*2
end

Nothing happens. It should be possible to store a widget name in a variable and then use that to reference the widget?

A string is not a widget, and is not automatically interpreted as the name of a widget.

When scripts run, widgets and cards are made available as lil variables, provided the widget or card's name is a valid lil identifier.

As I noted in #19, cards and the deck expose dictionaries (card.widgets and deck.cards) which offer an alternate way of accessing widgets by their string names.

Got it. This works:

on click do
x:"wanda fish"
card.widgets[x].text:card.widgets[x].text*2
end

Or, for the record, you could even do:

on click do
 x:card.widgets["wanda fish"]
 x.text:x.text*2
end