Okay, let's start with your most recent question: the difference between = and ==:
== is equality (e.g. a == 10 means "a is equal to 10", which may or may not be true)
= is assignment (e.g. a = 10 means "assign the value of 10 to a") and is the
only way to assign a value to a variable. However, in VC, = can also be used to check for equality, based on context. For example
if (a = 10) will check to see if
a has a value of 10. This can also be presented with a more confusing example:
a = b = c. What this will actually do is check to see whether
b is equal to
c and assign the resulting boolean value to
a.
I would personally recommend that you always use == to check for equality and = for assignment. In many other C-like languages, that is exactly how = and == work and following this convention can make your code easier to read and can help you transition to other languages more easily in the future.
In this particular case, though, you should actually be using >= operator. The reason is this:
flidance() has been hooked to retrace, so it gets called once per render loop, but you're checking for equality with the logic loop (timer). These two are
*not* in lockstep with each other. So on one render pass,
timer - zeit may be 26, but the next render it may be 28 and you'll have skipped 27 completely, meaning that your event (the color change) will
*never* occur.
The second thing that stands out (which is what you're actually asking about) is where you're calling
setLucent() from. Your assumption that it's only getting called once and then reset is correct. What you want to do is set the lucent every draw (by calling
flidance(), in this case), not when you
hookretrace it (which doesn't actually call
flidance at all, it just sets it up to be called on each retrace thereafter). Moreover, McGrue is correct that you'll want to "reset" the lucent after drawing with lucency, otherwise everything drawn afterward will be drawn with that same lucency (unless / until it gets set by something else).
One other (very) small suggestion is that you can subtract 1 from the width and height of the RectFill() call. Because the screen coordinates start at 0 instead of 1, using screen's width and height as coordinates will actually go 1 pixel past the right and bottom of the screen. It's likely that the clipping region for the screen helps mitigate the cost from drawing outside the screen, but because lucent drawing is more expensive and you're drawing something screen-sized, it's worth the trouble to add two little "- 1"s.
Edit: according to Overkill, this does not actually help since the clipping rectangle is applied regardless, so you might as well let it do its thing. The code has been updated to reflect this.
All of these suggestions are represented and commented in the code block below:
void mango()
{
hookretrace("flidance");
}
void flidance()
{
if ((timer - zeit) >= 27) // Use >= here because timer and the retrace loop may not ever sync up the way you want
{
c1 = Random(0,255);
c2 = Random(0,255);
c3 = Random(0,255);
zeit = timer;
}
setLucent(20); // Set to desired lucent
RectFill(0, 0, ImageWidth(screen), ImageWidth(screen), RGB(c1,c2,c3), screen);
setLucent(0); // Reset lucent to prevent it "trickling through" the rest of your drawing
}
Edit: Fixed some stuff that Overkill noticed was incorrect. What a
jerk swell guy.