Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Lil Programming Questions Sticky

A topic by Internet Janitor created Oct 28, 2022 Views: 4,041 Replies: 153
Viewing posts 21 to 48 of 48 · Previous page · First page
(1 edit)

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.

i’d also like to know how to receive from stdin, if that will be possible.

Developer (1 edit) (+1)

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"]

hmm, guess i’ll have to mod C decker to do what I want then. Thanks for the info.

Is there a function for creating a font interface from a font string, similar to image[]?

Developer (2 edits) (+1)

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.

(1 edit)

In Interact mode, is it intentional that text copied between rich text enabled fields does not retain font formatting?

Developer

Yes. If a text selection consists solely of whitespace and one image, Decker will copy the image to the clipboard. Otherwise, Decker will copy the plain-text interpretation of the selection.

(+1)

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!

Developer(+1)

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?

(+1)

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!

Developer(+2)

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.

(+1)

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. 

Developer(+1)

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]
  • reading "foo.value" produces a rich text table.
  • "contextualize[foo.value] " calls the contextualize function with that rich text table and returns a modified rich text table.
  • the colon (:) is the assignment operator in Lil.
(+1)

As I anticipated, my issue was a syntax one and I wasn't properly calling "contextualize". I also unnecessarily added a comma delimiter to each of the rtext.make[] functions (I use Power Apps and JSON a lot with work). Everything is working as intended now, thank you!

(+2)

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!

Developer(+1)

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
end

And 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?

(+1)

Yes that does, thanks so much!

(1 edit)

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.

Deleted 138 days ago
Developer

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?

(+1)

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
Developer

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:

  • If your script is on the same card as the widgets it references, it isn't necessary to use a fully-qualified name like card.widgets.canvas1; canvas1 will do just as well.
  • If you want to modify a large group of widgets at the same time, as in the beginning and ending of your script where you hide all your animation frames, you could make a list of the widgets and then take advantage of the ".." syntax. For example:
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
  • It's possible to introduce "helper" functions to factor out repeated patterns. We could, for example, make a function that sleeps for a few frames and then displays a widget- inverted if it's a field, and otherwise solid:
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!

(1 edit) (+1)

A question a day ! (I'm trying hard to have something completed for the deck-month !!)

So, I'm using two things : 

1. The Interior Contraption (I can drag a canvas to show what's behind a card)

2. The Decker Dialogizer (I can display text on the bottom of the screen as in a narrative adventure)

What I'm trying to do is to display a text only once, when I enter a card. For this I use a checkbox called tooted, and I use this script on my card : 

on go card trans delay do
 c:deck.card
 send go[card trans (30 unless delay)]
 if tooted.value.1
  dd.open[deck o]
  dd.say["Premier texte."]
  dd.close[]
  tooted.value:!tooted.value
 end
end

The text is only displayed once BUT my interior contraption can't be drag anymore ! And if I delete this lines of script, I can move the interior contraption. 

Have you got an idea ? 

Developer

Hmm.

I suspect "tooted.value.1" should probably be "tooted.value~1" or even just "tooted.value", and you don't appear to be doing anything with the variable "c" or defining anything for the variable "o".

Dialogizer runs "synchronously", blocking most forms of input while its dialogs are open. You shouldn't be able to drag widgets around, click buttons, etc, while a dialog is open, but when you close the dialog and the initiating script finishes everything should be back to normal.

Is the problem that you want to drag the Interior while the dialog is open, or does it somehow cease working even after the dialog has been closed?

(2 edits)

A button "Start" on another card leads me to the "bedroom_n" card and set all tooted checkbox to 1.
Once inside "bedroom_n", a text is displayed, I click and it disappear, but after this, I can't drag the Interior. 

Developer(+1)

I'm not completely certain what's going on here without really digging into the whole deck, but it looks like there's a conflict between your use of "go[card]" to drive non-blocking animation and bob the navigation arrows and your wrapper for "on go ... end" that conditionally triggers a dialog.

It might be better to make those buttons contraptions so they can handle their animation in a self-contained way and reduce the amount of scripting you need on each card; perhaps you could modify the bob contraption to expose a click event?

Looks like a really ambitious project so far!

(+1)

Indeed, the problem was a conflict between the bob contraption and the dialogizer ! Now I can do what I wanted to ! Thanks !!

(2 edits) (+1)

I got a little problem ! 
I want to randomly play 4 sounds, but only when I'm on a specific card

I'm using this code on the script of my card

on loop do  
random["dove_1","dove_2","dove_3","dove_4"] 
end

But even when I'm moving to another card, the script keeps on playing randomly the 4 files.

How should I do to stop the sound playing when I'm not on my card ? 


EDIT : I found it ! I needed to add - play[0 "loop"] - when moving to another page ! sorry for this useless post 

Developer(+1)

The default handler for the "loop" event provided by Decker looks like this:

on loop prev do
 prev
end

This handler is why the background loop plays forever by default; every time the loop ends, this function asks for the same sound to be played again.

If you write a deck-level script (File -> Properties -> Script...) which defines a replacement:

on loop do
 0
end

Then the loop will stop on all cards that do not have their own "on loop ... end" handler which overrides the above.

Does that make sense?

(+1)

absolutely !

(2 edits) (+1)

And how do I lock and unlock a button with a command ?
I tried 

on click do
card1.widgets.button1.locked.1
end

but I can see it's wrong

(sorry for being that level of noob)

EDIT : damn, again I found it : card1.widgets.button1.locked:1

There's a weird issue with the tangent function, where tan(pi/4) = 0, but using approximate values, like tan(0.7854), you get an answer close to 1. sin(pi/4) and cos(pi/4) are unaffected. I guess this might be some kind of floating point issue with the pi constant, and for that reason I'm not sure if it's a bug or a kind of user error. 


Developer

Looks like a problem with prettyprinting floats, rather than arithmetic itself. Applied a patch.

Developer

The number formatting issue has been patched in v1.37

(+1)

That was quick! Thank you! 

Hi! I need to authorize access to a card only on condition that all the other cards have been visited. Do you have any tips on how I can do this easily? 

Developer (1 edit)

Hm. Well, the first step (if you haven't done it already) would probably be stubbing out keyboard navigation, with a card- or deck-level script that overrides navigate[] to do nothing, to make sure the player can't accidentally go to your "protected" card without using editing tools:

on navigate do
end

Then you need some way of keeping track of whether cards have been "visited". Several ways to handle this. If you had an invisible checkbox on every card that needed to be visited named "visited", you could record visits something like so in each card's script:

on view do
  visited.value:1
end

Or even handle it automatically with a deck-level script fragment (not inside a function handler, just bare):

deck.card.widgets.visited.value:1

Left bare, it will execute whenever *any* event is processed. On cards without a "visited" checkbox it will have  no effect.

Check if every card with such a checkbox was checked using a query:

if min extract value..value where value from deck.cards..widgets.visited
  # ...
end

The ".." can be read as "at every index". The minimum of a list of 1/0 values is equivalent to logically ANDing them all together.

And you might want a button somewhere for resetting all the visited checks:

on click do
  deck.cards..widgets.visited.value:0
end

The nice thing about this approach is that as you add new cards in the future, you can decide on an individual basis whether they need to be counted toward "visiting everywhere".

Make sense?

I don’t get where i’m supposed to enter the minimal number of cards visited to allow a new thing ? 

If i have a button, and if its clicked whereas all cards have not been visisted i want to display a text (with dialogizer) / and if the value is high enough another text is displayed, then go to the new unlocked card 

Developer(+1)

You originally stated your goal as "all other cards have been visited".

In the model I describe above, cards whose visitation can count toward the total are each given an invisible checkbox (with a consistent name) that keeps track of whether that particular card has been visited yet. Cards that do not have such a checkbox don't count toward the total, so for example you may not need one on a "title screen" card.

If you only want to know whether some threshold has been exceeded, the query I showed for checking whether all such cards have been visited can be modified to instead count how many have been visited, and compared to some threshold (say, 10) like so:

if 10<sum extract value..value where value from deck.cards..widgets.visited
  # let the player go to another card...
else
  # tell the player they can't go yet...
end

If you only kept a single counter somewhere to track card visits, there would be no way to identify repeat visits to the same card, which is probably not what you have in mind.

If you used a different naming convention (call some checkboxes 'visited1', some 'visited2', etc?) and modified the queries I describe accordingly, you could track several disjoint or partially-overlapping groups of "visited" cards.

(+1)

It's good for me !!!! 

Is there any way built in way to do networking over HTTP in Lil? I am trying to build a simple client for a simple messaging protocol called "Nostr" which is mainly websocket based. 

Developer

Not currently.

If you're familiar with JavaScript it is relatively straightforward to install new primitives in the Lil interpreter by modifying an HTML build of Decker. This thread includes an example of exposing browser localStorage to Lil.

Async communication is somewhat awkward; if you were to expose an API based on callbacks, like the underlying JS APIs, you could easily end up with Lil functions attached via closure to parts of a deck that have been modified or destroyed since the original call was performed. A polling-based system exposed on an Interface might be less error-prone.

Here's a sketch (untested) of a polling-based wrapper for XMLHttpRequests:

const pending_messages=[]
interface_messagebox=lmi((self,i,x)=>{
   if(ikey(i,'send'))return lmnat(([url,verb,text,id])=>{
     const x=new XMLHttpRequest()
     x.onreadystatechange=_=>{
       if(x.readyState!=XMLHttpRequest.DONE||x.status!=200)return
       pending_messages.push(lmd(['text','id'].map(lms),[lms(x.responseText),id?id:NONE]))
     }
     x.open(verb?ls(verb):'POST',url?ls(url):'')
     x.send(text?ls(text):'')
     return NONE
   })
   if(ikey(i,'poll'))return lmnat(_=>pending_messages.length?pending_messages.shift():NONE)
   return x?x:NONE
})

WebSockets add some additional complexity because the connections need to be persistent, but a similar approach might work.

Very helpful! Thank you and all the best for 2024.

Beginner question - is there a property on widgets to return the card that widget is contained in?  So, for example, so you could create a button that changes its text property to that of the name of whatever card it is within?

Developer (1 edit)

Widgets do not expose an attribute with a reference to the card that contains them. There are, however, several ways to accomplish what you describe.

Whenever a widget's event handler is fired, a number of variables will be in scope, including:

  • "me": the recipient of the event
  • "deck": the current deck
  • "card": the current card (there's some additional subtlety to this in Contraptions, which I will omit for clarity)
  • all of the widgets on the same card, according to their names
  • all of the cards in the deck, according to their names

So, for example, your button script might look something like:

on click do
 me.text:card.name
end

If the button happened to be named "myButton" and the card it was on happened to be named "myCard" you could equivalently say:

on click do
 myButton.text:myCard.name
end

Another way to access cards is via the deck. The "deck.card" attribute is the card that the user is presently viewing. Generally this will be the same as the "card" variable, but "deck.card" might be more up-to-date if you happen to go[] to another card midway through a script. Thus, we could also write the example as:

on click do
 me.text:deck.card.name
end

The mechanics of events are described in more detail in the Decker Reference Manual.

Does that answer your question?

(+1)

Yes! Thanks so much for the help. Decker is sick btw!

(1 edit)

EDIT: Also, sorry if I'm not so great at explaining haha ^^; I tried my best to explain it since it is somewhat complex...

How do I program a simple text adventure into Decker? I want to let the player input their response into the parser, press "GO!" and add an output (Like adding a ">" before copying their response to the game text area and adding another response that correlates with the response they entered as a normal text adventure would.) Here is what I made so far:

Developer

That's a pretty open-ended question. Text adventures can be as complicated as you want to make them. It's only a little bit more specific than "how do I program a video game?"

As a really simple starting point, if you have widgets like so:


You could add a script to the button (or to the card, since there's only one thing that can be "clicked") something like

on click do
  response:"i don't know how to %s, buddy." format input.text
  
  log.text: log.text, ("\n>%s\n" format input.text), response, "\n"
  log.scroll:999999999
  input.text:""
end

Obviously this doesn't interpret any commands, but it handles appending text to the log, ensuring the log is scrolled to the bottom, and resetting the input field each time. If you run it, you can get something like this:


For the parsing and formatting bits themselves, you might get a few useful ideas from the mini-twine proof-of-concept I posted earlier; it demonstrates parsing a markup format with Lil and building chunks of "rich text" on the fly.

The "Lildoc" script which is used to build Decker's HTML documentation from Markdown files might also be worth looking at: https://github.com/JohnEarnest/Decker/blob/main/scripts/lildoc.lil

Does any of that point you in the right direction?

(1 edit)

I don't know if this really has anything to do with lil, it's about the dialog contraption, so it's still a programming question. I am making a game in Swedish, so i need to use the letters Åå, Ää and Öö. Since Decker doesn't support them, I have made a custom font, replacing other less used symbols with them, though this, of course, requires rich text. When using r:dd.ask, is it possible for the alternatives to be rich text? I made this attempt, where field6, 8 and 9 all contain rich text:

r:dd.ask[   
field6.value   
(field8.value, field9.value)  
] 
if r~0     
 dd.say["placeholder"]     
 dd.close[]  
else       
 dd.say["placeholder"]       
 dd.close[] 
end

Decker would, however, display 8 and 9 in plain text and like this:


Menu is the font name. Do you have any ideas what could cause this?

Developer(+1)

The ideal place to ask questions or submit bug reports about Dialogizer is the Dialogizer thread.

Rich text is represented as a table. While the "," operator applied to a pair of strings will form a list of strings, it will concatenate the rows of a pair of tables into a single table. We need to be a little more careful when we want to create a list of tables.

The "list" operator can solve this problem; it wraps any value in a length-1 list. The "," operator will join those length-1 lists together instead of the values they contain. Try constructing your list of choices for dd.ask[] like so:

(list field8.value),(list field9.value)

If the only special thing about the rtexts is the use of a single particular font, you could alternatively give the choices as plain strings and set the "bfont" option when you set up dialogizer; this will apply the specified font as the default for all the dd.ask[] choices:

o.bfont:"swedishFontName"
dd.open[deck o]
...

For general dialogs there's also "tfont" for the default font of the body text in dd.say[] and dd.ask[] boxes.

Ah! Thank you. I guess it makes sense.

Hi ! 

On a card I have a slider, which can display values between 0 and 5. Next to it is a "validate" button.

I'd like the validate button to take the player to different cards depending on the value he chooses (so 6 different cards, since there are 6 possible values). I imagine this isn't very complicated, but I can't find the trick!

Developer(+1)

The go[] function is used to navigate to a different card.

There are three ways to specify the card you want:

  • by index: if you provide a number n, go[n] will navigate to the nth card in the deck, counting from 0.
  • by name: if you provide a string s, go[s] will navigate to the card with that name.
  • by value: if you provide a card c, go[c] will navigate to the card you provided.

Navigating by index is usually not a great idea, because adding or removing cards can easily break such a script. We'll use navigation by value for these examples.

The numeric value of a slider widget can be viewed through its .value attribute.

To turn a numeric index into a card value, we'll make a list of cards and index into it using the slider's .value.

To slightly simplify your example, let's say you have a slider named "mySlider" with a range from 0 to 2, and cards named cardA, cardB, and cardC.

Forming a list:

(cardA,cardB,cardC)

Forming a list and then indexing it:

(cardA,cardB,cardC)[mySlider.value]

So the full button's script could be:

on click do
 go[(cardA,cardB,cardC)[mySlider.value]]
end

And of course, if you want a smoother transition you can specify go[]'s optional arguments for a transition style and delay:

on click do
 go[(cardA,cardB,cardC)[mySlider.value] "BoxIn" 15]
end 

This kind of approach also works if you don't need/want all the destinations to be distinct. Consider:

on click do
 go[(cardA,cardA,cardB,cardC,cardB)[mySlider.value]]
end

Is that clear?

(+1)

Totally clear and perfectly works (as usual you're the boss)

I'd like to make a "search" game system, so players type something into the bar, then click on a card that contains the term (so far I've had no problems!). 

But to put an end to the game, I'd like their number of moves to be limited, so they can view say 10 documents (so 10 different cards) before automatically arriving at a new card that forces them to turn in an investigation report. What would be the easiest way to do this? 

The other idea I have would be to set up a countdown visible from all the maps, at the end of which you arrive at a final map, but I imagine that's a lot more complicated...

Developer

I'd make a locked and/or invisible field (or maybe a slider) somewhere to track the number of moves the player has remaining.

If you're displaying search results as a bunch of links in a field, you could make clicking a link count down the remaining moves by overriding the "link" event for the field. The default handler for link events is

on link x do
 go[x]
end

So you could instead give the field something like

on link x do
 moves.text:moves.text-1
 if moves.text=0
  go[theGameOverCard]
 else
  go[x]
 end
end

Side note: you can also write that conditional as:

go[if moves.text=0 theGameOverCard else x end]

This approach might be a little weird, though, since it ignores the user's final selection and surprises them with a game over.

If the cards you can get to via search have a "back" button, maybe it would make sense to test for game overs there, and navigate to the final card instead of the search page?

I'm using SearchEngine contraption, I'm not sure if I can "override" the links displayed in this prototype?

Developer

You'd need to modify the contraption prototype, but it's a very simple change. In the SearchEngine the results are displayed in a rich-text field named "o". It doesn't currently contain any scripts and simply relies upon the default "on link" behavior.

The main thing to be aware of is that within a Contraption you won't auto-magically have cards and widgets of the deck in scope as variables; You do have access to "deck", though, so you can use fully-qualified paths to reach out to a specific widget. e.g. "deck.cards.theSearchCard.widgets.theSearchCounter", and if you use go[] you can refer to cards by name (as strings) instead of value (as cards).

I've tried to make all the contraptions in the bazaar as generic and reusable as possible, but don't be afraid of hacking them up or making changes to suit a specific application. In the worst case you can always delete the prototype and re-import the reference copy.

I think I'm close to the solution, but I don't understand why when I write "moves.text:moves.text-1" -> the field displays "-1" instead of doing a calculation... 

Hi there!!! I've been loving playing with decker so far and have a  noobish(?) question. Is there a way we can edit and/or import are own animated brushes like the last 4 in the default palette?  I've looked around the Contraption thread as well as searching thru the forum. Thank you!! <3 

Developer (1 edit)

It sounds like you mean animated patterns. There isn't a built-in tool for modifying patterns, but Decker includes scripting APIs that could be used to build one. For example, the PatEdit contraption can edit patterns themselves, and the AnimEdit contraption can be used to configure animated sequences (patterns 28-31) of the static patterns (2-27). You could also set up animated patterns manually with The Listener.

If you actually mean brushes, the decker reference manual section "Brushes" describes how you can define your own. Decker comes with an example deck that contains several custom brushes.

(+1)

This is a question regarding scripting. I would like to have a button "toggle" between two states; revealing a widget A, then hiding a widget A, then revealing a widget A, etc. but don't know what the script for that would look like. And speculatively, would it be possible to add other elements so that the button might cycle between revealing widget A, to revealing widget B,  to revealing widget C, then back to hiding them all? Thanks in advance!

Developer (1 edit)

The first example is very straightforward: widgets have a .toggle[] method. If you call it with a single argument it will alternate the value of their .show attribute between "none" and the string specified ("solid", "transparent", or "invert"):

on click do
  a.toggle["solid"]
end

You can see more examples of .toggle[] in the release notes.

Cycling through displaying several different widgets is a bit more complicated.


One approach would be to test the .show attributes of widgets, find which one is currently visible, and then set the .show attributes of all the widgets in a group in order to advance to the "next" selection. The main issue here is it's very ugly and inconvenient to add more widgets to the cycle:

on click do
  if     "solid"~a.show a.show:c.show:"none" b.show:"solid"
  elseif "solid"~b.show b.show:a.show:"none" c.show:"solid"
  else                  c.show:b.show:"none" a.show:"solid"
  end
end

We can reduce repetition and make maintenance a bit easier by making a list of widgets of interest, scanning for them in a loop, and using an index modulo the length of the list to pick the next item:

on click do
  cycle:a,b,c
  current:0
  each wid index in cycle
    if "solid"~wid.show current:index end
  end
  cycle..show:"none"
  cycle[(count cycle)%1+current].show:"solid"
end

If we want to get really clever, there's also a "vector-oriented" way to handle that search instead of an each-loop. In general, multiplying a list of integers [0,n) by a length-n list containing zeroes and a single one will "mask out" the index of the one:

(0,1,2,3)*(1,0,0,0)   # (0,0,0,0)
(0,1,2,3)*(0,1,0,0)   # (0,1,0,0)
(0,1,2,3)*(0,0,1,0)   # (0,0,2,0)
(0,1,2,3)*(0,0,0,1)   # (0,0,0,3)

So we could compute "current" like so:


Giving a complete script as follows:

on click do
  cycle:a,b,c
  current:sum(range count cycle)*"solid"=cycle..show
  cycle..show:"none"
  cycle[(count cycle)%1+current].show:"solid"
end

If you want to include "don't show anything" in the cycle, you can add a "0" dummy element to the list of widgets; 0.show will always be 0, which is not equal to the string "show", and attempting to set the .show property of a number is likewise harmless:

on click do
  cycle:0,a,b,c
  current:sum(range count cycle)*"solid"=cycle..show
  cycle..show:"none"
  cycle[(count cycle)%1+current].show:"solid"
end

Does that answer the question?

Edit: one more note: depending on what you're trying to do it might be worth considering using a slider widget instead of a button; Sliders naturally represent choosing between a range of integers, which could represent an index into a list:

on change val do
  cycle:0,a,b,c
  cycle..show:"none"
  cycle[val].show:"solid"
end

See also, the enum contraption.

(+1)

This is great. Exactly what I was looking for (and more!) It's enlightening to see how many different ways their are to tackle a problem. Thanks so much for this John.

(2 edits) (+1)

Hi! I’m a bit stuck trying to figure out how to search for a substring inside a table. I’m thinking of a journal application where I have Date and Entry columns, and I was hoping to add a search function that returns rows that match a certain substring. Reading the docs, it looks like I can match the first part of the string by doing this:

select Date Entry where ("hi%m" parse Entry) from journal_list.value

But I can’t quite figure out how to match a string that doesn’t start at the beginning. 😅

Developer (1 edit)

The "in" operator can test whether a substring is present in a string:

 "upon" in "stars upon thars"
1

To use this on a column, we could define a helper function. While we're at it, this can also lowercase the column we're searching for a case-insensitive match:

on like needle haystack do
     each v in (list "%l")format haystack
         needle in v
     end
end

Allowing us to write a query like so:

ex:insert Date Entry with
     20210412 "Once Upon A Time"
     20220709 "There once were"
     20230101 "stars upon thars"
end
select where like["upon" Entry] from ex
# +----------+--------------------+
# | Date     | Entry              |
# +----------+--------------------+
# | 20210412 | "Once Upon A Time" |
# | 20230101 | "stars upon thars" |
# +----------+--------------------+

How's that?

(+1)

Amazing thank you so much for the help! I’m still getting used to Lil you can do so much with so little. I’m just now seeing this: “The each loop collects together the results of each iteration of the loop and returns them” 🤯

Developer

The absence of a direct equivalent to SQL's "like" operator has plagued me for some time, so in Lil v1.40 I decided to introduce a first-class equivalent. Using this operator, we can now perform the same type of case-insensitive search (as well as quite a few handy variations) without needing a helper function:

ex:insert Date Entry with
     20210412 "Once Upon A Time"
     20220709 "There once were"
     20230101 "stars upon thars"
end
select where ((list "%l")format Entry) like "*upon*" from ex
# +----------+--------------------+
# | Date     | Entry              |
# +----------+--------------------+
# | 20210412 | "Once Upon A Time" |
# | 20230101 | "stars upon thars" |
# +----------+--------------------+

If you prefer the previous way, it will be necessary to rename the "like[]" helper function, since "like" is now a reserved word. Sorry for any inconvenience!

Hello,

There's probably a trick for that, but I didn't find a way to create a single element dict:


("foo") dict ("bar") => {"f":"b", "o": "r"}



Whereas:

("foo", "baz") dict ("bar", "qux")


does the expected.


Developer

The straightforward way is to use the "list" operator, which wraps its argument in a length-1 list:

 (list "foo") dict (list "bar") 
{"foo":"bar"}

A fancier, more concise way (provided your keys are strings) is to perform an amending assignment to an empty list, like so:

 ().foo:"bar"
{"foo":"bar"}
(+1)

Thanks! very helpful!

Some cards in my deck have a field called "group" with a number in the text field.

In my deck, how would I go about selecting a random card that matches a specific group number and then send the player to that card?

Developer (1 edit)

To obtain a list of the cards with a particular group number you could use a query something like

c:extract value where value..widgets.group.text=2 from deck.cards

(Note that if a 'group' field doesn't exist it will behave the same as a card in group "0"; you probably want to count from 1 for your groups)

Given that list, you can pick a random item and navigate to some card like so:

go[random[c]]

Or, all at once,

go[random[extract value where value..widgets.group.text=2 from deck.cards]]

Does that make sense?

(+1)

Yes! Thank you.

(+1)

Is it possible to hide a column in a grid? I find myself having to use a lot of hidden grids and then selecting a subset of the columns into a visible grid. Which is fine enough, but I wonder if I'm misunderstanding the scope of variables or features of grids and maybe there's a way to not do this.

Developer

You can adjust the widths of the columns of a grid to hide trailing columns. In "Interact" mode, a small draggable handle appears between column headers:


You can reset the columns to their default uniform spacing with the "Reset Widths" button in grid properties.

Manually resizing column widths enforces a minimum size. You can set column widths to 0 programmatically via "grid.widths", but a 0-width column looks a bit odd; I'll make a note to fix that in the next release.

(+1)

Somehow I missed the grid.widths value in the grid interface. Thanks!

Developer

FYI i've patched the problem with 0-width columns in grids; that should now offer a fairly flexible option for visually suppressing columns without physically removing them from the underlying table. You can try it out now at the bleeding-edge source revision, and the fix will be incorporated into the v1.41 release; probably next week.

I'm having a hard time wrapping my head around arrays, maybe it's not what I actually need to be using. Basically I have two fields that I can enter text and I want to take each field and append them to an array that splits it all up by word. So "This is my text"  in field1 and "More text" in field2 would be ["This", "is", "my", "text", "More", "text"] that I could then manipulate.

Developer

Starting from the two fields you describe:

You can obtain the text of either field through its ".text" attribute. The "split" operator breaks a string on the right at instances of the string on the left and produces a list. Splitting one string on spaces gets us part of the way to what you're asking for. We can then use the comma operator to join a pair of lists.

" " split field1.text

The best way to experiment with this sort of thing is to use The Listener. Ask a "question", get an answer:

Another approach for gathering space-separated words from several fields would be to use an "each" loop:

Does that help point you in the right direction?

(+1)

This does! When looking at the docs I guess this made me think "split" and such were tied specifically to tables. But now I'm starting to wrap my head around this.

Developer (1 edit)

In general, for string manipulation the main tools Lil provides are:

  • drop, take, split, and parse for cutting strings apart into smaller pieces
  • fuse and format for gluing pieces together to make strings
  • like, in, <, >, and = for comparing and searching strings

...and a few of the more complicated utility functions functions in rtext do also apply to plain strings.

I may not understand fully how random works.

Say I have a table with 5 rows stored in 'temp'

random[temp,1] will usually get me a row with all the data, But sometimes it just results in the integer 1.


Why is that?
Developer

The Lil "comma" operator forms a list by combining the elements of its left and right arguments.

If you use this operator to combine a table and a number, the table will be coerced to its list interpretation (a list of the rows of the table, each a dictionary), and then combined with the number 1 (whose only element is itself), forming a list of several dictionaries and the number 1. Applied to such a list, random[] will occasionally choose the 1.

When you call a Lil function with multiple arguments, commas should not be placed between arguments. You probably meant

random[temp 1]

 Instead of

random[temp,1]

Furthermore, note that if you specify 1 as a second argument to random[] you will get a length-1 list as a result, whereas if you call random[] with only a single argument you will get a single value.

In preparing this post I have also observed that there is some inconsistency between native-decker and web-decker with respect to applying random[] to table values, which may have compounded the confusion; I'll have this fixed in the v1.41 release tomorrow. In the meantime the alternative is to explicitly crack the table into rows before making a random selection, like so:

random[(rows temp)]
(+1)

Thank you!

(+1)

Does random use a fixed seed? When I repeatedly run a lil script in lilt, random[range 15] returns 4 every time.

Developer

Lilt uses a fixed seed by default; this is a design decision inherited from K.

One simple way to randomize it would be something like

sys.seed:sys.ms

Note that Decker automatically randomizes the RNG seed at startup.

(+1)

Cool. Thanks!

What’s the best way to filter a list based on some predicate?

I was able to use “extract value where … from somelist” for some basic arithmetic, but when I throw a function into the predicate I get unexpected results (“value < f[value]” always seems to be true even though it definitely isn’t).

I’m wondering if I’ve misunderstood the “where” clause and it is only supposed to be used in table columns or something.

Developer(+1)

In the context of query clauses, column names refer to the entire column as a list. The "where" clause expects an expression which yields a list of boolean values. Arithmetic operators like =, <, and + conform over list-list and list-scalar arguments.

Depending on how a predicate is written, it might naturally generalize to operating on lists for the same reason. For example: 

on iseven x do 0=2%x end
iseven[5]
# 0
iseven[11,22,33]
# (0,1,0)
extract value where iseven[value] from 11,24,3,8
# (24,8)

If a predicate is only designed to operate on a single scalar value at a time, you can use the "@" operator to apply it to each element of a column, like so:

on seconde x do x[1]="e" end
extract value where seconde@value from "Lemon","Lime","Soda","Demon"
# ("Lemon","Demon")

This shorthand is semantically equivalent to

extract value where each v in value seconde[v] end from "Lemon","Lime","Soda","Demon"

(And of course in this particular case the "like" operator would be simpler:)

extract value where value like ".e*" from "Lemon","Lime","Soda","Demon"

Does that clear things up?

(+1)

Thanks! That does explain why it seemed to work sometimes and not others. I will give it another try. For the record, It looks like my skimming skills failed me, because I now see where this is explicitly noted in the docs:

When computing columns, you're working with lists of elements, and taking advantage of the fact that primitives like < and + automatically "spread" to lists. When performing comparisons, be sure to use = rather than ~! If you want to call your own functions- say, to average within a grouped column- write them to accept a list

It even calls out “where” in the next paragraph.

(+1)

Hi! I've been having a fun time messing around in Decker, and am now attempting something more game-y.

Specifically, I'd like to know if these are possible to do:

  • When Button X is clicked, have Button Y on a different card disappear/become hidden
  • When Button Z is clicked, unlock new dialogue on a different card (with the Dialogizer module)
I'm assuming it would be something like, "on click do: Button X = true"—but I'm not sure exactly what terms to use, so I would appreciate any help. Thanks!
Developer(+1)

Widgets have an attribute called "show" which controls their visibility; this can be "solid" (the default), "invert" (an alternate color-scheme), "transparent", or "none".

Suppose the button X is on card C1 and the button Y is on card C2.

You could give X a script for toggling Y's visibility:

on click do
 C2.widgets.Y.toggle["solid"]
end

Or a simpler version that just makes Y visible:

on click do
 C2.widgets.Y.show:"solid"
end

There are several other examples of doing this sort of thing in this thread.

To make clicking a button "unlock" dialogue or behavior elsewhere in the deck, you'll need to remember that the button has been clicked, and consult that record at a later time.

Checkboxes are just a special visual appearance for a button, so every button widget has a "value" attribute that can store a single boolean (0 or 1) value. Thus, we can use the button itself to keep track of whether it's been clicked. Suppose you've given the button Z on card C1 a script like so:

on click do
 me.value:1
end

A script on another card could reset Z's value,

C1.widgets.Z.value:0

Or test its value in a conditional:

if C1.widgets.Z.value
  # do something special
end

If you have lots of "flags" like this, it may be a good idea to centralize them in some kind of "backstage" card so you can keep track of them easily, and perhaps to give yourself a script for resetting the state of the deck.

Does that make sense?

(+1)

Makes sense! Thank you for the detailed walkthrough, that was all very helpful :)

Viewing posts 21 to 48 of 48 · Previous page · First page