What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Is it possible to pass a variable through a treesharp action?

guildoc

New Member
Joined
Feb 6, 2011
Messages
35
Reaction score
5
Howdy. Quick question - is it possible to pass a variable to a treesharp action?

I'd like to use 4 or 5 decorators and a single action (keep code a bit cleaner).

kind of like:

new checkAction1(new doAction(1)),
new checkAction2(new doAction(2)),
new checkAction3(new doAction(3)),

checkAction1 : Decorator { }
checkAction2 : Decorator { }
CheckAction3 : Decorator { }

doAction : Action { }

I've tried everything I can think of... is it even possible or am I on a fools errand here?

Thanks!
 
Code:
Action : TreeSharp.Action {

	private int Variable;

	public Action(int Variable) {
		this.Variable = Variable;
	}

}

Just a guess
 
Try something like that.

Code:
class MyClass
{
	public Composite CreateBehavior()
	{
		return new Sequence(
			new Action(
				delegate { DoThings(1); }
			),
			new Action(
				delegate { DoThings(2); }
			),
		);
	}

	private void DoThings(int argument)
	{
		// Do action stuff
	}
}
 
Hm, tried that...

Code:
private class doAbility : Action 
{
  private string abil; 
  public RunStatus doAbility(string abil) 
  {
    bool result = SpellManager.Cast(abil);
    return result ? RunStatus.Success : RunStatus.Failure;
  }
}
doAbility does not contain a constructor that takes 1 arguments.

I think I'm missing something...
 
Last edited:
figured it out - I just decided to forgo the whole base/action part and build a simple subroutine instead.

Thanks all for the pointers - gave me new stuff to work with.
 
Back
Top