David Roberson
Artist
|
This has popped up on several scripts I've worked on recently in FF10. Sometimes the code runs, and sometimes it doesn't. In this following example, it doesn't and I'm not sure if there's a real error there I'm not seeing or if this is a bug I should report. If I exclude the truncate() parts, it works, but then I could end up going beyond the 0-1 range with the output. I could live with that and use an inactive Invert to clamp output in the next step, but this function ought to be able to take care of it.
Code |
---|
function prepare()
contrast = get_slider_input(CONTRAST)
factor = (259 * (contrast + 1)) / (1 * (259 - contrast))
end;
function get_sample(x,y)
local r, g, b, a = get_sample_map(x, y, COLOR)
local nr = truncate(factor * (r - 0.5) + 0.5)
local ng = truncate(factor * (g - 0.5) + 0.5)
local nb = truncate(factor * (b - 0.5) + 0.5)
return nr, ng, nb, a
end;
function truncate(value)
if value < 0 then value = 0
if value > 1 then value = 1
return value
end; |
|
Posted: January 10, 2021 9:08 pm |
Details
E-Mail
|
Chris Goldthorpe
Chris Goldthorpe
|
I think that you need to terminate the if statements with "end"
if value < 0 then value = 0
end
if value > 1 then value = 1
end
|
Posted: January 10, 2021 9:34 pm |
Details
E-Mail
|
Rachel Duim
So Called Tortured Artist

|
Yep, here is more info:
4.3.1 – if then elseMath meets art meets psychedelia.
|
Posted: January 10, 2021 11:41 pm |
Details
E-Mail
|
David Roberson
Artist
|
Yep. I didn't catch it until I referred back to the manual. Rusty coding habits and inexperience tripped me up! It might have been easier if the log had linked to the problem line, but it was redirecting me to the very end of the script. That's why I seem to get the same error in other scripts. I suppose that qualifies as a "bug" but I suspect FF already knows about it.
Thanks for the feedback, Chris and Rachel!
|
Posted: January 11, 2021 2:41 am |
Details
E-Mail
|
Chris Goldthorpe
Chris Goldthorpe
|
David Roberson, the error can't be detected until the last line because that's the earliest that the compiler can be sure that the syntax is invalid. If you see something like
if value < 0 then value = 0
if value > 1 then value = 1
the second if statement falls within the first then clause and the compiler will be waiting for two "end" statements to follow. It would be nice if the error messages were more informative, i.e. missing end statement.
|
Posted: January 11, 2021 11:58 am |
Details
E-Mail
|
David Roberson
Artist
|
Good explanation for why the log links to the end of the script in such cases. It would be nice, though, if the syntax check responded first, since that usually does highlight the correct line. (Though, really, these are the things I should be learning to catch myself, so no complaints after thinking it through.)
Thanks again!
|
Posted: January 11, 2021 3:21 pm |
Details
E-Mail
|