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

TreeSharp Help PLZ

pbettell

Member
Joined
Mar 14, 2010
Messages
432
Reaction score
16
Hi all,
Need some help understanding something within TreeSharp.

What is the difference between "ret =>" and "ctx =>" within a decorator.
I.E.
How is
Code:
new Decorator(ctx => RoutineManager.Current.PullBuffBehavior != null, RoutineManager.Current.PullBuffBehavior)

different from

Code:
new Decorator(ret => RoutineManager.Current.PullBuffBehavior != null, RoutineManager.Current.PullBuffBehavior)

Thanks
pbettell AKA Ringo
 
short answer is there is no difference between the two examples. i believe a somewhat longer explanation would be if you've ever done something like "someList.Where(element => element.SomeValue == 42)" you're designating "element" as a temporary variable name which you can refer to in the predicate. in a Decorator, some "context" object is passed along that you could refer to (which is why some people name it "ctx"), but i don't have enough experience with HB to know what this object actually is yet, but from what i've seen so far nobody ever seems to actually do anything with this context object so my guess is people refer to it as "ret" because it's pointing to the expression on the right, which is sort of a return value.

at the end of the day, the whole "x => stuff == otherstuff" are anonymous (lambda) functions which are some nice syntactic sugar.
"someList.Where(element => element.SomeValue == 42)" could be rewritten as
"someList.Where(MyTestFunction)" where you define
Code:
public bool MyTestFunction(ObjectTypeThatListContains element) {
    return element.SomeValue == 42;
}

similarly,
Code:
new Decorator(ret => RoutineManager.Current.PullBuffBehavior != null, RoutineManager.Current.PullBuffBehavior)
could be rewritten as
Code:
public bool MyDecoratorTest(object ctx) {
    return RoutineManager.Current.PullBuffBehavior != null;
}
...
new Decorator(MyDecoratorTest, RoutineManager.Current.PullBuffBehavior)
...
assuming i understand this correctly based on the source code.
Decorator.cs - treesharp - Behavior Tree Implementation in C# - Google Project Hosting

this stackoverflow question might help too
.net - Predicate Delegates in C# - Stack Overflow
 
Last edited:
CodenameG, your attitude is nothing short of shit, everytime someone asks a question regarding code, you come back with some response that doesn't add anything except for insult to the situation.

First, I'm not writing a CC.
Second, the question was nicely answered by timglide, so you didn't need to add anything.
Third, your attitude will result in me posting this reply, then immediately going and pulling down my bot bases (RingoRaF suite), as i do not feel that this community is viable with a mod attitude such as yours.

Thanks timglide, your explanation privided the information I needed.
 
Removed CnG's post. There's no reason for the attitude (as you already said).

To give a short answer to those reading this thread; there's no difference between "ctx" and "ret". Both are just anonymous variable names. You can call it whatever you want.
 
Removed CnG's post. There's no reason for the attitude (as you already said).

To give a short answer to those reading this thread; there's no difference between "ctx" and "ret". Both
are just anonymous variable names. You can call it whatever you want.


Beautiful to see someone beginning to check his attitude. ;)
 
Back
Top