digitalmars.D.learn - getting the adress of a function by its name in string format
- nikki (17/17) Aug 30 2014 I would like to use json/or any other format for defining
- Philippe Sigaud via Digitalmars-d-learn (5/8) Aug 30 2014 If all your functions had the same signature, you could use an
- nikki (6/16) Aug 30 2014 I think that is the best solution indeed, there are only two
I would like to use json/or any other format for defining behavior trees. in that file format I can only use strings currently I just use the symbol directly but I was wondering how to 'find' them otherwise. float EAT_FOOD_DECISION(Agent agent){ return 1.0 - agent.hunger; } bool EAT_FOOD_BEHAVIOUR(Agent agent){ agent.hunger -= 0.1; } auto eat_food = Behaviour(&EAT_FOOD_BEHAVIOUR); auto eat_food_decider = Decider(DeciderType.Behaviour,&EAT_FOOD_DECISION[],eat_food); instead I would like to use "EAT_FOOD_DECISION" and "EAT_FOOD_BEHAVIOUR" and get the functions? Is that possible somehow?
Aug 30 2014
instead I would like to use "EAT_FOOD_DECISION" and "EAT_FOOD_BEHAVIOUR" and get the functions? Is that possible somehow?If all your functions had the same signature, you could use an associative array FunctionType[string] and initialize it: FunctionType[string] myFuncs; myFuncs["EAT_FOOD_DECISION"] = &EAT_FOOD_DECISION; But it seems they have different types?
Aug 30 2014
On Saturday, 30 August 2014 at 17:08:30 UTC, Philippe Sigaud via Digitalmars-d-learn wrote:I think that is the best solution indeed, there are only two types(BevaviorFunc and DeciderFunc), so two dictionaries instead. It also solves another issue of not having strings for naming the functions in logs.instead I would like to use "EAT_FOOD_DECISION" and "EAT_FOOD_BEHAVIOUR" and get the functions? Is that possible somehow?If all your functions had the same signature, you could use an associative array FunctionType[string] and initialize it: FunctionType[string] myFuncs; myFuncs["EAT_FOOD_DECISION"] = &EAT_FOOD_DECISION; But it seems they have different types?
Aug 30 2014