Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Lil Programming Questions Sticky

A topic by Internet Janitor created Oct 28, 2022 Views: 24,427 Replies: 394
Viewing posts 121 to 122 of 122 · Previous page · First page
(1 edit)

I want to use a slider in X card to copy # canvas image in Y then paste it in X canvas. Here's the code:

on change val do
   if me.value = #
      X.paste[deck.Y.widget.#.copy[]]
   end
end

But it doesn't work when I chage the slider value. Am I doing something wrong?

Developer

"#" is not a valid Lil identifier; it is used in Lil scripts to indicate a comment, which ignores the remainder of the line. Lil identifiers are described in the Lil Reference Manual as follows:

Variable and function names may contain any alphanumeric characters (as well as ? and _), but must not start with a digit. 

If you give a widget a name which is not a valid identifier, it will not be automatically available as a local variable, but it can be accessed by name from the card's ".widgets" dictionary:

card.widgets["#"]

Your description of what you're trying to do is inconsistent and unclear. If the idea is to- for example- index into images stored in a rich-text field named Y and paste the image corresponding to the value of the slider ("me") onto a canvas named X, you could use something like:

on change val do
 X.paste[Y.images[val]]
end
(1 edit)

I'm using a slider to switch between images that I want to copy from one set of canvases into a single canvas. I'm not using a ritch text field.

Developer (1 edit)

Presuming the canvases are on the same card and have a naming convention like "c1", "c2", "c3", "c4" and the slider is set to an integer range between 0 and 3 you could write something like

on change val do
 canvases:c1,c2,c3,c4
 X.paste[canvases[val].copy[]]
end

I ended up using a field anyways, lol.

That said, I got a new question, how do I script a button to add or subtract from the existing value of the slider?

Developer(+1)

Presuming a slider named "slider1", you could give a button a script like

on click do
 slider1.value:slider1.value + 1
end

This situation is very similar to one of the examples in The Decker Guided Tour and one of the examples in the introductory primer in the Lil Reference Manual.

(+1)

Thank you.

on click do
 slider1.value:slider1.value - 1
 slider1.event.change[val]
end

I tried using this code to change the value of the slider and execute this script:

on change val do
 Sphere.paste[Assets.images[val]]
 if me.value = 0
    button1.show:"solid"
    button2.show:"solid"
 else
    button1.show:"none"
    button2.show:"none"
 end
end

There is a range from 0 to 4 for the images in a field going down. But, for some reason, the 0th image gets pasted and not the third in the field.

I want it to paste the images in the order of values in the slider with each click and not skip to zero.

(+2)

I think you need to send the event to slider1 in a slightly different way:

slider1.event["change" val]

There's another post on the forums explaining more here.

And you'll also need to define what val is in this context. That could be in either script.

For now I put both changes in button script:

on click do
 slider1.value:slider1.value - 1
 val: slider1.value
 slider1.event["change" val]
end
(+1)

Thank you!

Viewing posts 121 to 122 of 122 · Previous page · First page