Struggling with Local Variables
BlitzMax Forums/BlitzMax Beginners Area/Struggling with Local Variables
| ||
Hi all, I'm working on a very simple project, trying to get the hang of BM. One thing I'm really struggling with is the use of local variables. Say I want to gently fade in the alpha from 0 to 1 via an if then loop such as: If fade<1 Then fade:+0.02 End If SetAlpha fade And this is itself within part of the main loop, where do I declare the 'fade' variable? If I declare it within the loop, it 'resets' to 0 everytime it's declared. I can get around it via global variables, but surely this isn't the way to do it efficiently? Cheers! |
| ||
You could declare it before the loop, or you could create a type that handles this kind of effects. I don't think there are other ways to do it (I could be wrong though). |
| ||
Stick it in a function/method and label it global. That way it will be "global" to the function/method, and the value will be kept between each call, but it won't be visible from the main loop.. |
| ||
Ah, didn't think of 'globalising' it within a function. I like to 'compartmentalise' all my work into functions, so this'll be ideal. |