Scope resolution operator...

BlitzMax Forums/BlitzMax Programming/Scope resolution operator...

matibee(Posted 2010) [#1]
Here's something I didn't know until I wrote a test for this post, so I may as well share it now...

I have a custom sprite type that has it's own SetAlpha method. When I come to draw it I need to call the Blitz version of SetAlpha, not the type method. Is there a way to break out from the out of the current scope?

The answer is Yes, and it's dead simple. Prefix the call with a period ".". See sprite.Draw()



I'd never come across scope resolution in BMax (other than Self and Super) and at first assumed it didn't exist :/


Oddball(Posted 2010) [#2]
I use this all the time. I thought it was common knowledge. You can also name a specific module if you have several with the same function names.
brl.Max2D.SetAlpha value
I don't think it's a sensible practice though as it can get quite confusing.


Galaxy613(Posted 2010) [#3]
Interesting, I knew about Self, but this is pretty cool. :D


xlsior(Posted 2010) [#4]
I use this all the time. I thought it was common knowledge. You can also name a specific module if you have several with the same function names.

brl.Max2D.SetAlpha value



I've used that on occasion too, to work with two modules with conflicting commandsets...

Kind of stumbled across it through trial-and-error though, I don't remember actually seeing the manual describe that functionality anywhere.


AnthonyB(Posted 2010) [#5]
Neat! I had no idea that this worked. I will be using this in the future! Thanks for the share! :)