1
\$\begingroup\$

I'm trying to create a pseudo turn based battle system in the Unreal Engine (think Final Fantasy style).

I'm trying to avoid the Enemies and the players attacking while another animation is in progress. I thought the most simple solution is to have a flag somewhere that the player controllers check before starting an animation, and set it to a value before they start, and then reset it when they've finished.

However, I could see this leading to race conditions if two controllers (AI or player) try to access the variable at the same time, then both start their animations.

If I was writing this in Java I'd obviously use synchronized methods, but I haven't come across anything like that in UnrealScript. Is there another way to avoid this? Its probably not the end of the world, as its a pretty unlikely occurance, but I'd like to try and avoid it completely if possible.

\$\endgroup\$
  • \$\begingroup\$ "pseudo turn based?" It's either turn based or it's not, don't complicate your life =) Maik Semder left your answer below, and a good one it is. \$\endgroup\$ – Patrick Hughes Feb 15 '12 at 18:32
5
\$\begingroup\$

obviously use synchronized methods, but I haven't come across anything like that in UnrealScript

Unreal script is only allowed and runs only in the main-thread, so there is no need to add synchronization objects to Unreal Script. In other words, two lines of script code can never access a variable at the same time from different threads, so no worries about race conditions in Unreal Script :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.