How do I make a turn based battle system?

How do I…

Make a turn based battle system where the player can move when the enemy does their attack

What is the expected result

I’m looking into making a turn based battle system where the player can move when the enemy does their attack on the player

What is the actual result

I used the “Ask AI” option (and I should’ve known better) and now, this code is just confusing me and making me lost on how to improve it. Any help on how to change this and give me the desired results would be appreciated.

Hey!
Just letting you know, I updated your post title to fit better, as “Something’s Wrong here” isn’t very descriptive :smile:

3 Likes

Hi - I would use a scene number variable ‘turn’ to control things. It looks as if you’re using a scene boolean that links to the enemy boolean. Have another variable ‘number of players’
i would have 0 as initial - plays intro
1 as player turn
2 as enemy turn
turn=0 - show text - set text to ‘Ready? Press any key!’
any key pressed turn add 1
turn=1 - turn on player controls. start timer
shot fired or timer >limit then turn add 1
turn>1 - pick all enemy, enemy id=turn-2, start object timer of enemy. turn on enemy movement and allow shot to be fired.
shot fired or object timer of enemy>limit then turn add1
turn>number of players then set turn to either 1 or 0.
this also means you can easily add more enemy and number them and link that number to the ‘turn’ variable
you can then also do things like turn=-1 is a cut scene - create objects from external layout over the top and then delete then again and set turn back to 0
you could have turn=-2 as a death scene etc

3 Likes

Heavy use of state machines and trigger once. Look into state machines if you have yet.

Late reply, but should I delete the “currentTurn” variable then and replace it with the two variables that you mentioned?

Variables in general is still something I’m lost with.

Hi … everyone’s different. I would as lts essentially a sequence (but a sequence of 2) and so I think of it in terms of numbers but I see people use a text variable where I would use a number variable. If you use a number then you can add or subtract 1 and compare it to another number variable. The way I mentioned above it’s easy to add another enemy.
The downside with numbers is that it’s more abstract and you can forget what they represent…so put notes in the comments.

Its well worth getting to grips with manipulating number variables and using arrays and structures …if you want to be able to have full control over things.

1 Like