How would you do an action tree in godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rafeu
:warning: Old Version Published before Godot 3 was released.

In the board game that I’m redoing digitally (Meeple War), buildings are what could be called “action trees”.
Abbey
Each turn, the worker will move one space to the right, choosing his path when he has to.
When he reach a symbol, the corresponding action occurs. Then when he moves again, he return to the first space. And it continue this way until the building get destroyed or replaced. What would be the more efficient of doing it since I have ten or so buildings to do?

:bust_in_silhouette: Reply From: ingo_nikot

i would us an dictionary. they can be build like trees.
they can also be loaded via json, so you can easyly modifie them without changeing and rebuilding your code.

here an example for 1 card, if you need x cards you put this stuff into and array and itterate over it.

var a_card_actions = {
	"start": {
		"up": {
			"sword":0,
			"hat":0
		},
		"down":{
			"house":0
		}
	}
}
    
var worker_a_steps = ["start"] #an array were we store the path of the worker

    #get current option for worker_a (we "walk" the path):
var actions = a_card_actions
for step in worker_a_steps:
	actions = actions[step]
#if 0 we are at the end of the path
if actions != 0:
	#array of all possible actions [up,down]:
	print(actions.keys())
            #call your code to present the player what he can do
else:
	pass #there are no actions left, call your code to do what happens then

#workers current position, -1 gives you the last array item:
print(worker_a_steps[-1])

#somewere else: code were you let the player decide which action he schould take
#...

#move worker down (here you would use the player input):
worker_a_steps.append("down")