Skip to main content

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

Welcome back, Dakota!

The active card is always available as "deck.card", and for scripts on a card or widget it can also be referred to simply as "card".

deck.card.widgets.widget_name.attribute_name

From within a contraption, "card" refers instead to the contraption instance itself, but you can use "card.parent" to walk up to the surrounding card that contains the contraption. (The same is true for using someWidget.parent to get a reference to the card the widget is on.)

Thus, a script inside your contraption might contain something like

card.parent.widgets.widget_name.attribute_name

If you want your contraption to be reusable in other projects, you might consider avoiding "hardcoding" the name of the other widget it accesses. If so, one way of doing this is to make contraptions send events to "card":

card.event["interrogate"]

And then put the more situationally-specific code in an event handler on the "outside" script of the contraption instance:

on interrogate do
 widget_name.attribute_name
end

The "template script" in a prototype's properties panel can help suggest to users that contraption instances will be fed certain events. 

There's nothing inherently wrong with doing this the more direct way instead of using events, of course; just noting alternatives!

It's also worth briefly mentioning- in case you're unaware- that a Lil expression like:

deck.card.widgets.widget_name

Is a shorthand for

deck["card"]["widgets"]["widget_name"]

So if you ever need to indirectly reference something by name you can write part of the expression in this expanded, bracketed form and replace the contents of the brackets with some subexpression:

deck.card.widgets[widgetpicker.value]

Does that help clear anything up?

(+2)

That does! Thank you so much!