''Auto Update! ' 'M.Laurenson/Defoc8 ' 'There are plenty of situations were you'd like certain objects to autmatically update 'per frame, without having to explicitly call an update method..the sample code below 'shows one way you might achieve this.. ' ' functions and globals within a type are bound to the type, not the instance.. ' these contructs can be accessed via the type name - myType.update(), myType.counter. ' they may also be accessed by instances, though it is important to remember these ' contructs are shared across all intances.. Type myType Global counter:Int=0 'var bound to type not to instance. Function update:Object(id,data:Object,context:Object)'function bound to type not to instance. counter=counter+1 EndFunction Method New() If(Not counter) AddHook(FlipHook,myType.update) EndIf EndMethod End Type Graphics(640,480,0) myObject:myType=New myType 'create an instance to register the hook function While(Not KeyHit(KEY_ESCAPE)) Cls() DrawText(myType.counter,0,11) Flip() Wend End
auto updating objects
BlitzMax Forums/BlitzMax Programming/auto updating objects Oooh, so how do hooks work? And what kinds of hooks are available?