Not logged inOpenClonk Forum
Up Topic Function pointers

This board is threaded (i.e. has a tree structure). Please use the Reply button of the specific post you are referring to, not just any random button. If you want to reply to the topic in general, use the Post button near the top and bottom of the page.

Post Reply
In Response to Günther
static const HitEffect = {
NextHit = nil;
func Hit () {
  // this is the object
  Awesome();
  var fn = this.Hit;
  this.Hit = GetEffect(HitEffect).NextHit;
  var r = this->Hit();
  this.Hit = fn;
  return r;
}
func Start(obj) {
  // this is the effect
  if (obj->GetEffect(HitEffect))
    return obj->RemoveEffect(this);
  NextHit = obj.Hit;
  obj.Hit = Hit;
}
func Stop(obj) {
  // this is the effect
  obj.Hit = NextHit;
}
}

One could probably imagine some library solution that would reduce the boilerplate a bit, but having the engine do the job would be easier. And would work with multiple instances of an effect on the same object. (Though the Real Solution(tm) to that would be closures. With closures one could also reduce the boilerplate to a single function call, at the cost of one wrapper function per callback. Not really worth it...)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill