Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

Hello! I think this question is probably rooted in my coding experience being from Java, so I keep trying to apply incorrect formatting here. 

I have a field widget called "name"  on card "A" where I want the player to type their name, and I have a locked field widget called "hellotext" on card "B" where I want it to say "hello [name] how are you?" 

Ive been trying to do this with the following code in B's card script but I keep getting the output "0" in "hellotext"

hellotext.text: "Hi " + deck.cards.A.widgets.name.text + " how are you?"

I also tried 

hellotext.text: fuse "Hi ",deck.cards.A.widgets.name.text, " how are you?"

but that gave me the error " 'fuse' is a keyword, and cannot be used for a variable name."

Sorry for such a simple question but I'm really stumped!

(1 edit) (+1)

The "+" operator in Lil is exclusively for addition. It will coerce strings into numbers in a best-effort fashion, which is why you're getting zero:

"5"+3               # 8
" 2.3" + "1Hello"   # 3.3
0+"Hello"           # 0

The "fuse" operator is binary; it expects a left string argument to intercalate between elements of a right list argument:

":" fuse "A","B","C"   # "A:B:C"
"" fuse "A","B","C"    # "ABC"

Assigning a list to a field's ".text" attribute will implicitly concatenate the elements of a list together, as a convenience. The following are equivalent:

hellotext.text:"" fuse "Hi","There"
hellotext.text:        "Hi","There"

Cards are normally in scope by name, so you don't typically need a fully-qualified path to reach a widget on another card. The following will be equivalent from a card/widget level script:

deck.cards.A.widgets.name.text
           A.widgets.name.text

Does that help?

If you aren't already, I strongly recommend using The Listener to try expressions out piece-by-piece as you develop.

(+1)

That does! Thank you so much :)