Tips for Organizing/Simplifying this spaghetti?

Hi! I’m new to programming and have been playing around with Unreal Blueprints trying to learn. I’m making rock, paper, scissors. The code for checking if you win/lose got a bit messy and required lots of copying/pasting, and I figured I could learn a better way to do things. If you have any tips/advice, I would love to learn. Thank you.

There are multiple ways you could do it. There is no exact solution to this. It can be one or a combination of many types of systems or variables. For instance, you can utilise the use of a switch or enumeration. You can also use functions, macros and boolean checks.

It is up to you how you want to design it to make it more readable.

1 Like

One option is as shown below. Three variables of the same Enumerator, with the selector variable (Choices) being a map (to allow names to be converted to numbers). Then compare Enums or maths to arrive at the winner.




1 Like

Set up a string array variable for choices like this

Then you can “convert” choices to number values (their index in the array), and use math formula to determine the result :

If math too hard, skip it and just expand the switch to cover all cases after the substraction. Might be even more optimized because less nodes is generally better in blueprints…

3 Likes

MODULO FTW!

:flexed_biceps:

1 Like

Thank you for all your help! I already had Enumerators created for Rock Paper Scissors, but I was pretty ignorant about how to use them usefully. I had no idea about “Find”, for example. Your explanation expands my understanding of their uses innumerably. :slight_smile:

Nice! This looks very clean. I wanted to ask this question because I knew when I was copying and pasting a million times that I was being inefficient, and learning how to clean up the mess would teach me, a complete novice, a lot. Thank you for your examples. I will put in some time to learning how this works.

Edit: Okay, I think I get it! This whole “modulo” business is working (I’m over here writing down the equations with paper and pencil like in the olden days), and now I will look into WHY it works because I definitely have no idea. lol

You’re welcome.