//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

if (!isObject(CounterBehavior))
{
   %template = new BehaviorTemplate(CounterBehavior);
   
   %template.friendlyName = "Counter";
   %template.behaviorType = "Game";
   %template.description  = "Handles a counter value and ticks up or down";

   %template.addBehaviorField(count, "The value", int, 100);
   %template.addBehaviorField(counter, "The text object to display the count in", object, "", t2dSceneObject);

	%template.addBehaviorField(maxScore, "The maximum score you can achieve on this level", int, 90000);
	%template.addBehaviorField(nextLevel,"The next level to load", string,"");

}

// this is where we modify the text this behavior generally will be attached to. generally it
// will be called from a CountOn**** behavior 
// TODO: add the "ticker" aspect to the behavior
function CounterBehavior::ModifyCount(%this, %value)
{

   %this.count += %value;

   if (!isObject(%this.counter))
      return;
   %this.counter.text = %this.count; 
echo(%this.count);
echo(%this.maxScore);

	if(%this.count == %this.maxScore){
		sceneWindow2D.schedule("1","loadLevel",expandFilename(%this.nextLevel));
	}//end if
	

}
