How do I make array play in order?

Hey everyone,

So ive been trying to develop a game for uni project and have been making an attack command. Within the attack command I implemented an array which plays the attack animations in a random order using the random int node.

However I want to play them in a specific order, can anyone help me or point out which node to use to achieve this?

Many thanks!

i don’t know why u want specific order.
but, u can create array for store order index.
for example, 2,1,0
then for loop get this index for play.

What @MilionX suggested worked wonderfully once for me, I’d say that’s the way to go.

or,create a key map struct. key store index, value store animation.
then, for loop 0 to struct length.
then, use find function to get value of key map struct

hey thanks for commenting but to be honest im not to sure i know what your on about however ive gone as far as to make an int array. am i on the right tracks lol? Im abit of a noob tbh only started using ue4 a year ago here and there.

Also the reason i want it to play in order is i want the animations to play in order as a set 123 cick sequence.

if u don’t use for loop.
u need to create a new variable names current index to store index.
then each time for play, increase the current index.

I really appreciate you helping me out :slight_smile:

So ive done this which is what i think u wanted me to do for solution a however it doesnt seem to work… Instead it just plays the first animation which in this case is 0.

1 Like

try to make current index…
and new solution.

I didn’t want to interrupt @MilionX and I kinda feel bad about it because he gave you everything you need but you couldn’t grasp it. I’ll try to show you how Map variables work and you’ll see that you can figure it out by yourself.

Here, in this example, I’ve created a map variable with a string as a supplement.
image
I want to print “a, b, c” on the screen using this variable but my letters aren’t in order:
image
So, in the other side (the key side), I’ve put them in order using ints like so:
image
If you read the letters by following their numerical order you can read them as “a, b, c” and not “b, a, c,” and that’s exactly what we’re using the ForLoop for because it adds one to each iteration.

Here, by pressing a button, the letters are shown in order following their numeration:


This is the result (keep in mind that PrintString node always prints newer values on top)
image

Use the same logic for your project by replacing the letters by your animations.

1 Like

you @MilionX are an angel! It works exactly how i want it to… ive been trying to figure it out for hours haha and time is valuable when doing a uni assignment lol. Really appreciate the effort you put in to answer my question. Hopefully it will help others too and has given me a better understanding of how arrays can work together. Again thank you very much :slight_smile:

Wow thank you for that very good elaboration of what @MilionX was discussing. This has helped me understand a litter better on how the for loop and arrays work. My problem has been solved by @MilionX but i really appreciate you input and hopefully will help others :slight_smile:

1 Like

just to your comments and pictures are really going to help me moving forwards. I have also taken this method and applied it to the sounds the player makes when attacking within sequence to the attack array. I with use this method for alot of things :smiley:

Hey @Aumenn2003 @MilionX so I dont mean to be a pain and maybe i will work it out eventually but im trying to get the attackorder to reset to 0 if the player hasnt press the attack command for 3 seconds so i did this but obviously it didnt work. it seems like i get somewhere close just can never figure it out.

What are you using the AttackOrder variable for?

@Aumenn2003 Im creating a topdown template and using the attack order to sequence my attacks left swipe right swipe spin attack. im using play anim montage as a simple root motion solution to my attacks. so i want the character to got back to the first attack if the character hasnt attacked for 3 seconds. I hope you understand that and that i am also abit of a noob. however i do have a passion for becoming a game development so these answers you have given me are really good for my own development and helping uni studies :slight_smile:

Blockquote

What event are these nodes connected to? It’d be great if you could post the other half of the graph.


i have no test.
may be some mistake in Timetoreset + attacktime > gameseconds…
try to change <

1 Like

Suggest you use a timer for this. It will allow you to reset the 3 seconds after each attack and cancel when all attacks have been executed. Something delay node will not let you do.