YOUR ACCOUNT

Login or Register to post new topics or replies
David Roberson
Artist
Posts: 404
Filters: 36
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;
  Details E-Mail
Chris Goldthorpe
Chris Goldthorpe
Posts: 56
Filters: 13
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
  Details E-Mail
Rachel Duim
So Called Tortured Artist

Posts: 2498
Filters: 188
Yep, here is more info:
4.3.1 – if then else
Math meets art meets psychedelia.
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
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!
  Details E-Mail
Chris Goldthorpe
Chris Goldthorpe
Posts: 56
Filters: 13
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.
  Details E-Mail
David Roberson
Artist
Posts: 404
Filters: 36
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!
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,711 Registered Users
+18 new in 30 days!

153,531 Posts
+36 new in 30 days!

15,347 Topics
+72 new in year!

Create an Account

Online Users Last minute:

18 unregistered users.