Skip to main content

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

In Lil, the "+" operator is exclusively for addition. The "," operator joins strings into lists, and writing to the ".text" attribute of a field implicitly concatenates together the elements of a list. In a string literal, a backslash followed by the letter "n" is an escaped newline.

Putting this all together, you could write that fragment as:

on run do
 if (me.text = "hello") | (me.text = "Hello")
  log.text:log.text,"\nHello to you as well!"
 else
  log.text:log.text"\nI do not understand."
 end
 me.value:""
end

You could further simplify the conditional by factoring out the common parts of each subexpression:

on run do
 log.text:log.text,"\n",
 if (me.text = "hello") | (me.text = "Hello")
  "Hello to you as well!"
 else
  "I do not understand."
 end
 me.value:""
end

To make the initial comparison case-insensitive, you could use the "%l" formatting pattern to convert the input to lowercase:

on run do
 log.text:log.text,"\n",
 if "hello" = "%l" format me.text
  "Hello to you as well!"
 else
  "I do not understand."
 end
 me.value:""
end

Does that help?

(+2)

Yes! Very much. I was bashing my head over the "fuse" function and getting compounded text, lmao!

In other words, this helped me a lot and I am, once again, amazed at how simple the solution is.

Thank you!!!

So... I'm trying to use a grid cell's value to store variables. Here's the code:

on run do 
 if Data.cell(0,0)=1 & ("room" = "%l" format me.text)
  Log.text:Log.text,"\n\n","> ",me.text,"\n","You are in room 1."
 elseif Data.cell(1,0)=1 & ("room" = "%l" format me.text)
  Log.text:Log.text,"\n\n","> ",me.text,"\n","You are in room 2."
 elseif Data.cell(2,0)=1 & ("room" = "%l" format me.text)
  Log.text:Log.text,"\n\n","> ",me.text,"\n","You are in room 3."
 elseif Data.cell(3,0)=1 & ("room" = "%l" format me.text)
  Log.text:Log.text,"\n\n","> ",me.text,"\n","You are in room 4."
 else
  Log.text:Log.text,"\n\n","> ",me.text,"\n","I do not understand."
 end

And the Grid value is

Rooms
0
0
0
0

Which should produce "I don't understand" but it says, "You are in Room 1." No matter how I format the grid itself.

Am I doing something wrong?

(+1)

I think you’re a bit confused.

Looking things up in an array, or calling a function, uses square brackets rather than round brackets. So for example, if you want the grid to scroll until row 23 is visible, you’d do Data.scrollto[23], not Data.scrollto(23).

Data.cell tells you which cell is selected, it doesn’t give you the contents of the cell. If a cell is selected it returns its coordinates, otherwise it returns the pair -1,-1. Since it always returns a non-empty list, it’s always considered truthy. So an expression like:

if Data.cell(0,0)=1 & (whatever) alert["hi"] end

tests Data.cell (which is always true), evaluates the expression (0,0)=1 & (whatever) and discards the result, then evaluates alert["hi"].

I don’t think there’s an easy way to get directly from coordinates to a cell value, but you probably want to be looking up a specific column by name rather than position:

if Data.value[0].Rooms=1 & ("room" = "%l" format me.text)

Well, so much for using grids to hold values. Does this mean I have to flood the card with sliders and checkmark buttons?

(+1)

What kinds of values are you trying to store?

Just numbers.

(+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.