Store widget references in a variable?
gcanyon opened this issue · 3 comments
gcanyon commented
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?
JohnEarnest commented
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.
gcanyon commented
Got it. This works:
on click do
x:"wanda fish"
card.widgets[x].text:card.widgets[x].text*2
end
JohnEarnest commented
Or, for the record, you could even do:
on click do
x:card.widgets["wanda fish"]
x.text:x.text*2
end