Not logged inOpenClonk Forum
Up Topic General / Help and Questions / Timerfunc in object script
- - By Kandif [pl] Date 2013-06-09 09:25
I'm trying to do timer func "wait" in object script and I don't know why it doesn't work. It also doesn't display errors.

My code of function:

protected func FxWaitStart(){
  timewait=36*3;
  return 1;
}

protected func FxWaitTimer(object target){
  if(waitt==false){
                 Log("It doesn't display");
     return 1;
  }
  else{
    SetYDir(0);SetXDir(0);
    timewait--;
      if(timewait==(36*3)){
        CustomMessage("3", target, NO_OWNER);
      } 
      if(timewait==(36*2)){
        CustomMessage("2", target, NO_OWNER);
      }
      if(timewait==(36*1)){
        CustomMessage("1", target, NO_OWNER);
      }
   
      if(timewait<0){
        waitt=false;
        timewait=36*3;
      }
    return 1;
  }
}

waitt and timewait are local variables.

protected func Initialize()
{
  AddEffect("Wait", this, 100, 1);
}

What i have to change ?
I
Parent - - By Caesar [de] Date 2013-06-09 09:44
I guess timewait should be an effect-variable. Also, message 3 will not display, look at the order of assignment, decrement and check of timewait.

See also:
command_target:
[opt] Command target. If specified, all callbacks are executed in this object. Otherwise the callbacks are made without any object context.
Parent - - By Kandif [pl] Date 2013-06-09 10:00
But Log() also doesn't display despite that it's not use timewait :/.
So func at all don't run. :\
Parent - - By Caesar [de] Date 2013-06-09 10:02
Then probably the command_target thing applies. I'm not entirely sure, but your functions are protected (does that even still exist?), which iirc means they can only be called by the engine or the object itself, with object context.
Parent - - By Kandif [pl] Date 2013-06-09 10:21
I remove the acces modifer (protected) and func began to work. But the messages still don't display.
I change target to command_target:

AddEffect("Wait", nil, 100, 1,this);

func FxWaitTimer(object command_target){
  if(waitt==false){
     return 1;
  }
  else{
    SetYDir(0);SetXDir(0);
      if(timewait==(36*3)){
        CustomMessage("3", command_target, NO_OWNER);
      } 
      if(timewait==(36*2)){
        CustomMessage("2", command_target, NO_OWNER);
      }
      if(timewait==(36*1)){
        CustomMessage("1", command_target, NO_OWNER);
      }
   
      if(timewait<0){
        waitt=false;
        timewait=36*3;
      }
      timewait--;
    return 1;
  }
}
Parent - - By Caesar [de] Date 2013-06-09 10:24
Hm, maybe you should acquire a debugger in which you can evaluate the function step by step, see what your variables are, etc. I think, the eclipse plugin can do that.
Or, you do it the oldschool way and just add a ton of Log()s, printing every variable and every state.
Parent - By Kandif [pl] Date 2013-06-09 11:04
Well. Now it's work fine.

I noticed that the messages display on the centre of screen but i want to message over this object.

How to do it ?
Parent - By Kandif [pl] Date 2013-06-09 11:27
I didi it.

Thanks for help :D
Up Topic General / Help and Questions / Timerfunc in object script

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill