Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+5)

For your first question, a canvas gets the click event on mouse-down, and the release event on mouse-up, so you can make the canvas change colour while the button is held down:

on click pos do
 me.pattern:colors.red
 me.rect[0,0 me.lsize]
end

on release pos do
 me.pattern:colors.white
 me.rect[0,0 me.lsize]
end

(obviously you can do fancier painting than that if you want)

The release event also gives you the position of the pointer at the time the button was released, relative to the top-left corner of the canvas. If the position is below and to the right of the top-left corner, and above and to the left of the bottom-right corner, then it’s within the canvas, and you can do whatever the canvas-button is supposed to do:

if min (pos>0,0),(pos<me.lsize)
 alert["whatever I'm supposed to do"]
end

For your second question, I can’t easily spot an error (though I’m pretty sure you don’t need set); in this situation I’d wrap show[] around different parts of the code to double-check that the values being calculated were the ones I expected. show[] takes a sequence of expressions, logs them to the Listener, and returns the first one, so you can wrap it around expressions without changing how your code runs. So, this code will run exactly the same as the example above:

if min show[(pos>0,0) "<-- to the bottom right"],show[(pos<me.lsize) "<-- to the top left"]
 alert["whatever I'm supposed to do"]
end

…but produces this output in the Listener:

(1,1) "<-- to the bottom right"
(0,1) "<-- to the top left"

For your third question, the floor operator drops the fractional part of a number:

 floor 1.0,1.4,1.5,1.6,2.0
(1,1,1,1,2)

If you want round-to-nearest rather than always-round-down, you can add 0.5 before hand:

 floor 0.5+(1.0,1.4,1.5,1.6,2.0)
(1,1,2,2,2)
(+1)

Alrighty, I'm back! I've started putting all of your of the advice you've given to work, but I still haven't been able to get the If Statement to work. 

I used the show code to make sure that that score.text is receiving numbers properly, and I also used the floor function to make sure that there were no decimal points in the score, but that didn't seem to work either. I also tried switching the field to both Plain Text and Code, but that didn't seem to fix anything either.

One thing I have come to realize is that when i make it so that the score.text is supposed to be Less Than the given number, it will always activate regardless of the number larger or smaller. And it seems to work the opposite with Greater Than, with it never activating instead. (I also tried to set the number it's compared to to a negative one,  and the results were the same) If anyone has any ideas as to what is going on, please tell me cuz I'm getting a little desperate.

Anyways, thank you Screwtapello for the help. Even if I can't get that one system working, seeing my scores finally not have a bunch of little decimal numbers hanging off of the end has eased a sense of peace upon my soul, one which I cannot describe accurately with words alone. Your help is appreciated.

(+2)

The .text attribute of a field is a string. Comparing numbers to strings in Lil can have surprising results, because in this case Lil makes the comparison lexicographically:

3>"12"  # 1
3>12    # 0

To avoid this problem, you can use an arithmetic identity operation to coerce the string into a number before performing a comparison:

  myField.text  # "12"
0+myField.text  # 12

Alternatively, use the .data attribute of the field instead: this will ask Decker to interpret the contents of the field as LOVE (a superset of JSON):

myField.text     # "12"
myField.data     # 12
otherField.text  # "[11,22,33]"
otherField.data  # (11,22,33)

Yet another option would be to store numbers in Slider Widgets instead of fields; a slider's .value attribute is always a number. Does that help?

(+1)

I'll have to do some more research on what all this means, but I have gotten it working now. Thank you!I Like Your Funny Words, Magic Man - Meming Wiki