i know that lil has fuse, but how would i do something like `{x,"\n",y}/("hello";"world";"etc")` in k? i have a list of strings of arbitrary length and i want to combine them all into a single string by a delimiter. is there a way to do that?
To use K terminology, fuse is a dyad which takes a delimiter as its left argument:
"\n" fuse ("hello","world","etc")
"hello\nworld\netc"
":ANYTHING:" fuse ("hello","world","etc")
"hello:ANYTHING:world:ANYTHING:etc"
And you can handle even fancier cases with a recursive "format":
(list "ITEM<%s>") format ("hello","world","etc")
("ITEM<hello>","ITEM<world>","ITEM<etc>")
("\n","ITEM<%s>") format ("hello","world","etc")
"ITEM<hello>\nITEM<world>\nITEM<etc>"To make a hyperlink in a field, ensure that it is a "Rich Text" field (the default for new fields), switch to the Interact tool, and select a region of text within the field. You can then use the "Text -> Link..." menu item to create a hyperlink, which will be shown with a dotted underline. When you're finished editing, to make the hyperlinks "clickable" you must lock the field, by switching to the Widget tool, selecting the field, and choosing the "Widgets -> Locked" menu item.
Fields emit a "link" event when a hyperlink is clicked, which you can intercept with a script to do as you please. If you don't write a script, the default behavior is to go[] to the text you provided when you created the hyperlink. If that's the name of a card, it will navigate to that card. If it's a url like "http://google.com" it will ask the web browser to open a new tab.
Hope that helps clear things up!
Why does distinct not always return a list?
In the example for distinct elements given:
extract first value by value from "ABBAAC"
when all items are equal, this provides a single element instead of a single element list. I don’t know why, but in my head it seems more flexible to return a single element list.
This is what i ended up using instead, since select always returns a list.
There is another workaround here since selecting the first element of each group in () will give (0), the default value, but at least that makes sense.
on uniq x do
if x~() () else
t:select list first value by value from x
t.c0
end
end
I think the simplest way to get the edge cases you want would be using "()," to coerce lists or scalars to lists, and using "() unless" to coerce an empty result with "first" to an empty list.
(),extract () unless first value by value from "ABBBCD"
("A","B","C","D")
(),extract () unless first value by value from "AAAA"
("A")
(),extract () unless first value by value from ""
()
The former coercion is always valid, but the latter does require some care depending on the data; this is the nasty side of unifying nullity and a numeric value:
(),extract () unless first value by value from 1,1,0,5,1,2,0,1 (1,5,2)
Edit: and another approach entirely would be to use "dict":
range (11,22,33,0,11,22) dict () (11,22,33,0) range (11,11) dict () (11) range (0) dict () (0) range () dict () ()
Depending upon the context, you might not even need the "range".
Among other things, Decker 1.32 revises the behavior of extract to remove its problematic "automatic de-listing".
extract first value by value from ()
Now returns (), like it ought to have from the beginning.
If you have a canvas containing the image, you can change visibility using the show attribute:
canvas_name.show: "none"
canvas_name.show: "solid"
To show or hide it on a delay, there is a simple way and a more complex way.
The simple way uses the sleep function. It (mostly) pauses the whole program until it’s finished sleeping. For example, you could use it in a button’s click action:
# Simple, e.g. button script
on click do
card.widgets.canvas_name.show: "none"
sleep[60] # number of frames to sleep for
card.widgets.canvas_name.show: "solid"
end
Complex uses sys.ms and recursive go[] functions to allow other things to occur in the meanwhile. You’d need a hidden field to store some extra data. Here the image shows after 1s.
# Complex, with a field called hidden_time
# Button script
on click do
card.widgets.canvas_name.show: "none"
card.widgets.hidden_time.text: sys.ms
go[card]
end
# Card script
on view do
elapsed: sys.ms - card.widgets.hidden_time.text
if elapsed > 1000
card.widgets.canvas_name.show: "solid"
else
go[card]
end
end
Edit: solved!
Is there a way to include multiple where conditions?
Example:
data: select num:("1","2","3","4","5") parity:("odd","even","odd","even","odd") prime:(0,1,1,0,1) from 0

What I want:
extract num where parity="even" and prime from data
Edit: Of course I find it as soon as I post. The answer is brackets!
extract num where (parity="even") & prime from data
Plotting (or reading out) individual pixels on a Canvas (or an Image interface) is possible; just index or assign through them with an (x,y) pair as if they were a list or dictionary.
Plotting a large number of pixels will be fairly slow, since doing so will force the Lil interpreter to do a large number of serial operations. Both canvases and images provide a variety of higher-level methods for scaling, transforming, and drawing which operate upon pixels in bulk, and should generally be preferred, especially if the goal is any sort of realtime animation.
You can hide Decker's menu bar by "locking" a deck. In the main menu, choose "File -> Properties..". and then click "Protect..." to save a locked copy of the current deck.
In the deck file itself, this adds a line like:
locked:1
You can also manipulate whether a deck is locked on the fly by setting "deck.locked" in a script:
on click do deck.locked:!deck.locked end
(Careful, though; if you use scripts to lock a deck you haven't saved yet you might get yourself stuck!)
Edit: oh, and if you meant hide the menu bar while editing, pressing "m" on your keyboard while using drawing tools will temporarily toggle the visibility of the main menu, allowing you to draw "underneath" it.
The "write[]" functions in both Decker and Lilt can save image interfaces as .GIF images (including transparency and animation, if desired), and it can save sound interfaces as 8khz monophonic .WAV files.
The GIF files emitted by Lilt/Decker tend to be quite large, as they make no effort to compress their image data, so it may be desirable to use ImageMagick, Gifsicle, or a similar GIF optimizer to process their output.
It's also possible to write out arbitrary binary files by using an Array interface, but this is more involved.
There isn't currently any kind of volume control; volumes are effectively "baked into" the amplitude of a sound's samples.
A slightly clumsy workaround would be to make a copy of an existing sound on the fly and use sound.map[] to rescale its samples. Assuming the deck contains a sound clip named "sosumi":
on play_scaled name vol do r:-128+range 256 play[sound[deck.sounds[name].encoded].map[r dict floor vol*r]] end on click do play_scaled["sosumi" 1] # normal volume sleep["play"] play_scaled["sosumi" .5] # half volume sleep["play"] play_scaled["sosumi" .25] # quarter volume sleep["play"] play_scaled["sosumi" .10] # 1/10th volume end
for an interactive adventure, how would you save a text input as a string variable for the player character's name ? i understand that it would start with a field.. say the variable for the string is playerName, and the field itself is called inputPlayerName.. would it just be the following in the script for the field?
playerName: ""
playerName: inputPlayerName.text
?? i can't test it because i also don't know how to print a string variable in a field.. simple things but still getting to grips!
In Decker, persistent state lives in widgets. If you want to remember anything beyond the scope of an event handler, it should be stored in a widget. For example:
| Type of Data to Store | Appropriate Representations |
| String | Field text |
| Ranged Number | Slider value |
| Arbitrary Number | Field text |
| Boolean (true or false) | Button value, any Widget's visibility |
| Image | Canvas, Rich Text Field (encoded as inline image) |
| Table | Grid value, Field text (encoded as CSV) |
| Dictionary or List | Field text (encoded as JSON) |
| Position or Size | any Widget's bounding box |
If you want to remember something without showing it to a user, you could use invisible widgets, or widgets on a hidden card.
The walkthrough and examples in this thread might be helpful to you.
I recommend checking out The Listener as a way of interactively trying short snippets of code. You can use the Listener to poke and prod at the contents of a deck or card and verify behaviors before you write a script.
The print[] and show[] Built-In Functions can be used to log information (formatted text or arbitrary Lil values, respectively) to the Listener for debugging. The alert[] function can sometimes be handy for debugging because it pauses the current script and displays text to the user. The panic[] function stops scripts completely, but can likewise be a tool for peering into the workings of complex scripts.
Does any of that help?
hello- i'm so sorry to do this, but i've just spent the last 4 hours trying to figure out how to put a string variable in a field (i.e. player types in their character's name -> that name appears in text when the game or NPCs address the player's character) and i just can't? figure it out?? thank you so much for your response, i did manage to grok that you can just use the field itself as the variable (using the listener to figure that out!!) but actually taking that text and putting it in a sentence in a field is just beyond me.. i've read the reference manuals, looked at examples, gone thru the community threads and have now decided to swallow my pride and ask how you would 'embed' a string variable in a different field? like "hi [playerName], it's nice to meet you" or something like that?
sorry, i am very aware that i've been asking a lot of questions.. this is the most ambitious thing i want to do, so i don't imagine i'll be asking too many more!
No worries. Asking "obvious" questions in a public forum like this helps future users and lets me know about potential documentation/usability problems so I can continue to improve Decker.
There are a few different ways we could approach using the value of one field to update another. For starters, let's take a look at string formatting.
The Lil "format" operator takes a formatting string on the left and one or more parameters on the right. Let's see a few examples in the listener:
"Hello, %s. How's it hanging?" format "Alice"
"Hello, Alice. How's it hanging?"
"%s missed your call; they were busy %s." format ("Phil","gardening")
"Phil missed your call; they were busy gardening."
Each "%s" in the formatting string is replaced with a string on the right, in order of appearance. There are lots of other formatting codes and features available for dealing with numbers, zero-padding, case conversion, etc, but for the moment we can ignore them.
Now, let's say we have two fields on the same card: "name" and "reply":

There are a few ways we could approach updating "reply" when "name" is changed. One way would be to add a script to "name" and use the "on change" event:
on change do reply.text:"Hi, %s. I hope this example makes sense!" format name.text end
It would also be possible to do the same thing when a button is clicked, etc. If "reply" was on another card, we might have to specify the "path" to it:
on change do otherCard.widgets.reply.text:"Hi, %s- how's it going?" format name.text end
Both of these approaches are "push"-based: something explicitly happens to the name field and our script reaches out to other fields in response. A different way to think about it would be "pull"-based: logic on individual cards which reach out to other widgets and update themselves. For example, we could have an "on view" script on our "other card" which updates reply whenever a user travels to that card:
on view do reply.text:"Hi, %s- how's it going?" format firstCard.widgets.name.text end
Either way works.
Does that get you "unstuck"?
I am running decker on bash in linux with ./c/build/decker, How do I print to stdout from that process?
I have tried
shell["/usr/bin/env bash -c \"echo asdas\""]
shell["echo asdas"]
shell["echo asdas > /dev/fd/1"]
which simply returns 0 and do nothing. I am not sure how it works.
print["adasda"] just prints inside the decker interface.
Decker does not have the ability to execute shell commands or otherwise interact with the host system without explicit user permission; "shell[]" and similar functions are part of Lilt, which has a similar but distinct set of APIs from Decker itself.
As it happens, there is a way to print to stdout from Decker in the latest source revisions- the "app.print[]" and "app.show[]" functions. Note that this feature is not part of Decker v1.31, the current release at time of writing.
There is presently no mechanism for polling from stdin. The closest analogy might be to use the alert[] function:
alert["please input a string:" "string"]
Not directly, no.
The Array, Image and Sound interfaces can be encoded as strings or reconstituted from strings via their "constructor" functions- array[], image[], sound[]. All of these are "free-floating" value-like objects that have no connection to or awareness of a deck.
Fonts are always part of a deck. The deck.add[] function can be used to create new fonts or make a copy of existing fonts, and deck.remove[] can likewise remove an existing font from a deck, which will as a side effect modify any widgets previously referencing said font. In Lilt, you can have access to multiple deck interfaces at the same time, so it's possible to copy fonts between decks.
It is technically possible to obtain encoded font strings- indirectly- via deck.copy[] and card.copy[], since those functions produce the same JSON-encoded string blobs you get when you copy cards or widgets manually, and correspondingly it is possible to use deck.paste[] and card.paste[] to indirectly add fonts or prototypes to a deck. In either case, manually parsing the copied representation of cards or widgets is a hack; the format used is subject to change in the future.
The ideal way to distribute Decker fonts, like modules, is to package them as decks. The other alternative is to copy a widget and share the "%%WGT0 " representation of that widget, along with any fonts and/or prototypes it may depend upon.
Having a blast working within Decker, but coming up short in trying to figure out how to turn a substring within a rich text field into a hyperlink from an onclick event. I know how to make text a hyperlink from the Text menu option, but I want to call a function that will sometimes change the text property of a field to a string containing a hyperlink. Hopefully that makes sense!
I think I follow you.
Copying rich text from one field to another requires accessing their "value" property. Let's say we have rich text fields name "target", "a", and "b". The "a" field contains a link, and the "b" field does not:

In the button above I have a script like this which randomly picks between the value of "a" and "b":
on click do target.value:random[(list a.value),(list b.value)] end
In this example, the values each need to be wrapped in a sublist with the "list" operator before joining them together with "," to prevent the rich text tables from being fused together into a single table.
The "a" and "b" fields could be hidden from view (Widgets -> Show None), and this approach generalizes to any number of alternative texts.
If you want to programmatically modify existing rich text to insert links it's a bit more complicated. Rich text is represented in Decker as a table, and the rtext interface contains some functions that can make it easier to manipulate such a table. If you wanted to change the styling of a specific range of characters within a field, you could use rtext.span[] to grab the text before and after your region of interest, retaining their existing styling, rtext.string[] to extract a region of interest without its styling, rtext.make[] to create a new styled chunk (including a hyperlink or inline image), and rtext.cat[] to glue all the pieces back together. If this is a road you need to go down I can try to furnish a more detailed example if you clarify your requirements. The dialogizer demo deck uses rtext functions to build its index on the fly.
Does that help at all?
That absolutely does, thank you! I realize though that I could have done a better job providing context. I'm migrating a project that generates content for a tabletop RPG from something I built in Twine to Decker. A lot of random[] functions.
For a lot of the cards I'm working on, there's a contextual link between them that's based around a single word. In the below case, the word "Alien" in the Anecdote field would ideally be hyperlinked to a card titled Aliens, which would have a similar list of fields with randomly selected values in fields. I initially tried including link[aliens] in the array, but that just caused the aliens card to load upon clicking the button that contained the array.

These results are never a composite of multiple results, but just a fixed list of potential results, just in some cases there's a "contextual link" to another card. So as far as the solutions you provided, I could have "link fields" that contain the few instances of when a link makes sense within the card and just use *.text as the array value in those cases, right? I'm willing to do this programmatically if it'll be a cleaner solution, though. Thank you again!
Just to make sure you're clear on the distinction, a field's .value attribute is a table, and a field's .text attribute is a string:

An rtext table can contain hyperlinks, inline images, and multiple fonts, but a plain string cannot. In many situations that ask for an rtext table you can supply a string and it will be "widened" into rtext, but it will all be in the default font. If you copy the .value of one rich text field to another it will preserve its formatting, but if you copy the .text you will flatten it out into a plain text representation.
(For anyone with web development experience, field.value versus field.text is loosely similar to element.innerHTML versus element.innerText.)
Decker 1.34 introduced a new "rtext.replace[]" utility function that might be handy. If you're working with a lot of text, links, and cards, it might be useful to write a deck-level utility function that finds certain keywords in a string or rtext table and replaces them with appropriate links, which you could then call whenever you populate a field. For example, perhaps something like this:
on contextualize text do db:insert keyword replacement with "Alien" rtext.make["Alien" "" "About Aliens" ] "Weapon" rtext.make["Weapon" "" "Weaponry" ] "Snacks" rtext.make["Snacks" "" "Delicious Treats" ] "Zombo" rtext.make["Zombo" "" "https://zombo.com"] end rtext.replace[text db.keyword db.replacement] end
There's basically no limit to the possible complexity here (for example, you could automatically populate the keyword list by inspecting the titles of cards in the current deck), so it's up to you to choose what makes sense to you and is reasonably convenient for your purposes.
First off I really appreciate your time in providing practical solutions. I gave this my best shot before returning here but every attempt I made at implementing the utility function you provided, at either the deck level down to the control itself, did not seem to work. I could get it to work within the Listener, but any table expressions seemed to do nothing outside of Listener. I'm sure I'm missing something, but I couldn't find a solution or workaround.
Are you writing the result into a widget?
If you had a rich text field named "foo" which contained some of the words defined in the table for contextualize[], you'd apply it to the field something like this:
foo.value:contextualize[foo.value]
Hi I'm working on a small game very loosely inspired by Her Story. The player types a keyword into a search bar "display.text" and if valid it takes them to a new part of the game. Very simply I am doing this by creating cards and if the player types in the name of the card it will take them there. I used the following script on the button.
on click do
go[ display.text "SlideLeft"]
end
Is there a way for me to check for invalid entries so I can display an alert? Currently, it doesn't do anything. I'm not sure if there's a way to create a list of valid keywords and check from that, or else check from the list of cards that are there and go from there.
Thanks!
Sure- there are several ways to approach something like this!
The "in" operator can be used to check a string against a hardcoded list of valid options:
on click do
if display.text in ("Keyword1","Keyword2","Keyword3")
go[display.text "SlideLeft"]
else
alert["404: Page not found."]
end
endAnd it is also possible to obtain a list of valid card names from the deck; deck.cards is a dictionary from card names to cards:
on click do if display.text in deck.cards go[display.text "SlideLeft"] else alert["No such card, I'm afraid."] end end
It might be a good idea to make the comparison case-insensitive if a user is typing free input. The easiest way to handle this would be to make sure the card names are all lowercase and then to convert the user input to lowercase with the "format" operator before doing any checks:
on click do t:"%l" format display.text if t in keys deck.cards go[t "SlideLeft"] else alert["I don't know anything about that."] ends end
Yet another option is to make a dictionary to associate one or more keywords with destination cards; this provides more options for "forgiveness" in input handling:
on click do words["reindeerflotilla" ]:"puzzle1" words["reindeer flotilla"]:"puzzle1" words["reindeer" ]:"puzzle1" words["smashthestate" ]:"puzzle2" words["smash the state" ]:"puzzle2" t:"%l" format display.text if t in words go[words[t] "BoxIn"] else alert["that's bogus!"] end end
Does that make sense?
I running into a somewhat unexpected behavior for a list of lists. Here is what happens in the listener:
eqs:((list 4, 2, 1, 3), (list 16, 4, 1, 12), (list 8, 1, 0, 0)) # listener prints back the list ((4, 2, 1, 3), (16, 4, 1, 12), (8, 1, 0, 0)). So far so good e:eqs # listener nicely print the list again ((4, 2, 1, 3), (16, 4, 1, 12), (8, 1, 0, 0)) e # listener prints the actual value of e: 2.718282. Why??? # I have also tried, with the same amount of success :( e:each eq in eqs end
How can I copy a list of lists? And why do I get this decimal value assigned to e even though the listener prints back the list that I'm trying to copy into e?
Edit:
I found the issue, e is a constant so even though Lil doesn't complain about me assigning a value to it the assignment doesn't actually happen and fails silently.
Could you describe what you're trying to accomplish in a bit more detail?
Is the idea that you'd just be stacking copies of images on top of one another repeatedly, or is it more like "gradually reveal a series of layered images"? Do you want this effect on a single card, or is it something you want to repeat in a variety of places with different images?
Oh sorry, I deleted my post because I found a solution (which is, I believe, really messy but it works approximatively...)
To summarize : I launch a song (divided into 6 part (witch 3-witch4 -witch5-witch6-witch7-TapeOut)
I want to display images and texts one after the other, they appear one on top of the other in a somewhat chaotic fashion.
I tried this on my play button :
on click do play["witch3"] card.widgets.canvas1.show: "none" card.widgets.canvas2.show: "none" card.widgets.canvas3.show: "none" card.widgets.canvas4.show: "none" card.widgets.canvas5.show: "none" card.widgets.canvas6.show: "none" card.widgets.field1.show: "none" card.widgets.field2.show: "none" card.widgets.field3.show: "none" card.widgets.field4.show: "none" card.widgets.field5.show: "none" card.widgets.field6.show: "none" sleep[120] card.widgets.canvas1.show: "solid" sleep[120] card.widgets.field1.show: "invert" sleep["play"] play["witch4"] sleep[120] card.widgets.canvas2.show: "solid" sleep[120] card.widgets.field2.show: "invert" sleep[100] card.widgets.canvas3.show: "solid" sleep[100] card.widgets.field3.show: "invert" sleep["play"] play["witch5"] sleep[120] card.widgets.canvas4.show: "solid" sleep[120] card.widgets.field4.show: "invert" sleep[120] card.widgets.canvas5.show: "solid" sleep[120] card.widgets.field5.show: "invert" sleep["play"] play["witch6"] sleep[120] card.widgets.canvas6.show: "solid" sleep[120] card.widgets.field6.show: "invert" sleep[120] card.widgets.canvas7.show: "solid" sleep[120] card.widgets.field7.show: "invert" sleep["play"] play["witch7"] sleep["play"] play["TapeOut"] card.widgets.canvas1.show: "none" card.widgets.canvas2.show: "none" card.widgets.canvas3.show: "none" card.widgets.canvas4.show: "none" card.widgets.canvas5.show: "none" card.widgets.canvas6.show: "none" card.widgets.canvas7.show: "none" card.widgets.field1.show: "none" card.widgets.field2.show: "none" card.widgets.field3.show: "none" card.widgets.field4.show: "none" card.widgets.field5.show: "none" card.widgets.field6.show: "none" card.widgets.field7.show: "none" end
This approach absolutely works, and is very straightforward. A "synchronous" animation script like this is often the easiest.
I can offer a few tips that could make such a script shorter and easier to maintain:
on click do parts:(canvas1,canvas2,canvas3,canvas4,canvas5,canvas6,field1,field2,field3,field4,field5,field6) parts..show:"none" # ...the rest of the animation goes here... parts..show:"none" end
on reveal delay target do sleep[delay] target.show:if target.type~"field" "invert" else "solid" end end
Which would then turn the main script into:
on click do parts:(canvas1,canvas2,canvas3,canvas4,canvas5,canvas6,field1,field2,field3,field4,field5,field6) parts..show:"none" play["witch3"] reveal[120 canvas1] reveal[120 field1 ] sleep["play"] play["witch4"] reveal[120 canvas2] reveal[120 field2 ] reveal[100 canvas3] reveal[100 field3 ] sleep["play"] play["witch5"] reveal[120 canvas4] reveal[120 field4 ] reveal[120 canvas5] reveal[120 field5 ] sleep["play"] play["witch6"] reveal[120 canvas6] reveal[120 field6 ] reveal[120 canvas7] reveal[120 field7 ] sleep["play"] play["witch7"] sleep["play"] play["TapeOut"] parts..show:"none" end
Perhaps you could go even further, making a function that played a music segment, revealed several items in sequence, and then waited for the segment to complete:
on phrase audio parts do play[audio] each row in parts sleep[row.delay] row.part.show:if row.part.type~"field" "invert" else "solid" end end sleep["play"] end on click do parts:(canvas1,canvas2,canvas3,canvas4,canvas5,canvas6,field1,field2,field3,field4,field5,field6) parts..show:"none" phrase["witch3" insert delay part with 120 canvas1 120 field1 end] phrase["witch4" insert delay part with 120 canvas2 120 field2 100 canvas3 100 field3 end] phrase["witch5" insert delay part with 120 canvas4 120 field4 120 canvas5 120 field5 end] phrase["witch6" insert delay part with 120 canvas6 120 field6 120 canvas7 120 field7 end] phrase["witch7" insert delay part with end] play["TapeOut"] parts..show:"none" end
Of course, abstraction adds some complexity, and might make it harder to introduce new exceptions to the rule if you continue to modify the script. Always choose the approach that feels the simplest to you!