+1 vote

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?

in Engine by (49 points)

1 Answer

+1 vote
Best answer

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")
by (289 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories