Skip to main content

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

You can store a bunch of numbers in sliders and checkmark buttons, but you can also store them in a regular field with the .data attribute:

field1.data:
 (list 0,0,0,0,0),
 (list 0,0,0,5,0),
 (list 0,7,0,0,0),
 (list 0,0,0,0,0)

field1.data[2][1] # evaluates to 7
field1.data[1][3] # evaluates to 5
field1.data[4][4] # evaluates to 0

The actual text in the field looks like [[0,0,0,0,0],[0,0,0,5,0],[0,7,0,0,0],[0,0,0,0,0]]

(1 edit)

And I can use that data for if-statements? Like

if field.data[2][1] = 5
 (whatever)
end

And do I have to write "list" for each array or can I name those lists?

(+2)

You can use that data for if-statements, or anything else you want.

The list makes each row a separate list, so in field.data[2][1] the 2 picks one of the rows, and the 1 picks an item from within that list.

The way you should organise your numbers depends on how you want to use them. If you just want a list of numbers to look up, a simple flat list might be fine. If you want a two dimensional grid of numbers, you can use nested lists (as described above) or maybe a Canvas, or a chunk of the card’s background (as discussed previously). If you don’t need to store information about every single possible thing you could look up and just want to record the most important ones, you can use a dictionary:

treasures[3,5]:"mirror"
treasures[2,7]:"beads"
treasures[1,4]:"sword"

field1.data:treasures

# ... later ...

t:field1.data[playerpos]
if t alert["You found the %s!" format t] end

If you have a bunch of things with different values for the same properties - for example, every monster has an X coordinate, a Y coordinate, and an amount of health - then you probably want a grid after all.

And can I rewrite the data with commands? I tried doing that with

me.data[(Row number)][(Column number)]:(some number)

Where the phrases in parentheses are arbitrary numbers. but it doesn't seem to work, so, I tried rewriting the entire table with

me.data:
 (list 0,0),
 (list 1,0)
if Command.text = "north" & "%l" format Command.text & (me.data[1][0] = 1)
 me.data:
  (list 1,0),
  (list 0,0)

Which should be parsed as if north, whether capitalized or not, were to be ran and the me.data of the cell is 1, then the entire table will be rewritten.

I'm also thinking of ditching the table format for a list one instead.

You can rewrite the data with commands, but it gets complicated for reasons I don’t think I fully understand.

field1.data:(list 1,2),(list 3,4)

# returns (1,5), but field contents unchanged
field1.data[0][1]:5

# copying the data into a Lil variable lets us modify it
newlist:field1.data
newlist[0][1]:5

# Now we can put it back
field1.data:newlist

(The bit that’s confusing me: according to Lil, the Functional Language, Lil values are immutable, and Lil, the Decker Language advertises various interfaces as being mutable - but the actual behaviour we see in practice here is the other way around! I’m guessing it’s something to do with the way assignments work, but I don’t really understand what.)

(1 edit) (+1)

Interfaces are only "aware of" direct attribute reads and writes.

# read:
field1.data
# write
field1.data:expr

When you read field1.data, the result is an immutable value- in your example a list of lists. Deeper indexing can "amend" that value, but it's no longer connected to the interface. Conceptually these lines are all equivalent:

field1.data[0][1]:5
(field1.data)[0][1]:5
((list 1,2),(list 3,4))[0][1]:5

An indexed amendment produces a modified copy of the original immutable value. If the root of the expression is a variable, its contents is updated. In some cases this may look like a mutation, but anything that referred to the original value will still see the unmodified copy:

foo:11,22,33
bar:foo
bar[1]:99

foo # (11,22,33)
bar # (11,99,33)

Does that help clarify?

(+1)

Ah, I think I see.

  • In the ’mydict.data[0][1]:5case, Lil traces from the originalmydict` variable down into the nested list, and so after creating an updated sublist, it can trace all the way back up to the original variable and update that too.
  • In the field1.data[0][1]:5 case, field1.data produces a data structure out of (from Lil’s point of view) thin air, and so Lil doesn’t know how to update it.

Is that right?

If the root of the expression is a variable, its contents is updated. In some cases this may look like a mutation, but anything that referred to the original value will still see the unmodified copy…

I originally tried to illustrate Lil’s immutable, functional nature by modifying a nested value and showing the original variable still had its original value, but… Lil was too smart for me, and the variable was updated to point at the modified value. I also considered using the “assign A to B, modify A, B is unchanged” example, but that just looks like a copy of the value is made immediately, rather than being copy-on-write.

I am still amused by the irony that interfaces make a better illustration of Lil’s immutable values, for the wrong reason. :)

Correct.

You can break the connection between a variable and the "strand" of an indexing expression by wrapping part of the prefix in parentheses, forcing it to be evaluated first, separately from the following parts of the strand. Consider these cases:

a:11,22,33
b:a
# these are 'simple' assignments;
# 'a' and 'b' both refer to (11,99,33)

a[1]:99
# evaluates to (11,99,33),
# 'a' now contains (11,99,33)
# 'b' still contains (11,22,33)

(b)[1]:88
# evaluates to (11,88,33),
# but the contents of 'b' is unchanged.
# equivalent to (11,22,33)[1]:88

And this wouldn't be syntactically valid at all, since it has neither a direct variable name at the "head" of the strand nor any indices at which to amend:

(b[1]):77

But we can do weird-looking things like this, amending the empty list at an index to create a singleton dictionary:

().foo:"bar"
# evaluates to {"foo":"bar"}
# equivalent to ()["foo"]:"bar"
(+1)

If what you want to store is specifically a 2d array of numbers, use a canvas; you can index into it with a pair of (x,y) coordinates:

# read a pixel:
myCanvas[0,1]

# write a pixel:
myCanvas[0,1]:12

All I'm hearing right now is that it's better for me to just make a separate card, call it "Brain" and just cram it with buttons and sliders to use as variables to keep track of. Which, the more I try to make this interactive fiction engine, is becoming more appealing as I do so.