You should
(a) select the random number ONE time at the start of the function (setting it to a variable like “var AnimationChoice : int = GetRandomInt(0,4)”; the way you are doing it is going to give you weird results.
(b) look into a “case” statement to do this correctly: Case | Epic Developer Community (epicgames.com)
(c) As a general strategy get each small part of your code correct before combining them into bigger sections. The “Print” statement is your friend.
Thank you very much for your helpful input. I will look into this further. I forgot where I read it, but I read somewhere that the print is a memory hog, I dk maybe it is wrong
I am new to code so any information is greatly appreciated
You can put in print statements to test each section of code. One that section is tested to run perfectly, then pull out the print statements and go on to a larger section of code.
I would suggest you start with writing one simple function maybe selecting one random number 1-4 and printing each result out on a separate print line (use “case”), then once that function is tested out, try something harder. Keep your efforts at about ten new lines of untested code at maximum.
It’s easier to debug ten lines than sixty lines, especially if you are bound to make multiple errors. With practice you will get proficient.
Coding is like practicing the piano: work on your scales before you try to play a whole song.
Is it possible to give me an example of how to use case?
Print is for the edit version only, it doesn’t go out to the public from my understanding
Yep, a lot of coders get fancy with debug statements, but if you are starting out Print is much less trouble. Just ‘Print(“I’m entering the function!”) ‘ can save you a world of grief.
I will try to look at it when I’m at my PC tomorrow, most languages have a ‘case’ switch statement so that you don’t have to nest a zillion ‘if’ statements together.
The one section that I noticed as way off could be corrected with…
@editable GroundAtackCinema : []cinematic_sequence_device = array{}
PlayRandomAttack()<suspends>:void=
if (Cinema: cinematic_sequence_device = Shuffle(GroundAtackCinema)[0]):
Cinema.Play()
Sleep(2.0)
else:
Print("You forgot to load elements into 'GroundAtackCinema' in the editor!")
…You put all of your attack elements into an array (you can add as many as you like) and ‘PlayRandomAttack()’ will play one at random. It will only fail if the array is empty (most likely because you forgot to add elements into the array when you placed the device in your level.
Note that there are a lot of ways of doing this (including ‘Case’ if the actions on the random choice were different, rather that just playing an animation and sleeping for two seconds.)
Note: ‘Shuffle’ is in the same Random module as your random int function was pulled from. “Shuffle(GroundAtackCinema)[0]” takes the first element from the shuffled array.
You are correct, however the sleep wasn’t adjusted yet til I had the boss move to closest player fixed. All the attacks will have a different sleep duration, because they are all not the same amount of time.
You are awesome for helping me out though. Have you figured out an example of how to write a “case” example in verse?
In that case you can make a float array with the durations and select the index of the animation and matching duration and end up with
GroundAtackCinema[Choice].Play()
Sleep(CinemaDuration[Choice])
Or do as I do and make the animations approximately the same and sleep for the longest one.
My boss has 62 animations lol… I just went through and picked my favorites for this project.
They all have different sleep duration though
Case documentation is on this page, most of the way down (ctrl-f for search)
I appreciate your help. Ya’ll are awesome… Now if y’all could point me into the direction of making my move to work with get closest player. Like from all of you helping me so far, I know how to call the get closest player. But I still don’t understand how to make the rotate to and move to use it. I only know how to make the RT and MT go to a set person, like [0].
Cause the deal is, I have a pit and spawners are at the top. I don’t want the boss to track the players at the top cause then he will move to that location either by floating or walking in air. The top of the pit doesn’t allow shots fired for one and two it just looks bad.
I kinda wish everything was in blueprints cause I was decent with those lol
Sorry it has been a minute since I last posted here. I had to move homes. So I wasn’t able to use case… I keep getting errors with it. I read the documentation extensively and still can’t figure it out. I did get my other issue sorted out though. I was wondering what you think of this code I made.
PlayRandomMeleeAtt()<suspends>:void=
if (GetRandomInt(0,1) = 0):
PlayRandomSet1()
else:
PlayRandomSet2()
PlayRandomSet1()<suspends>:void=
if (GetRandomInt(0,1) = 0):
PlayAttack1()
else:
PlayAttack2()
PlayRandomSet2()<suspends>:void=
if (GetRandomInt(0,1) = 0):
PlayAttack3()
else:
PlayAttack4()
PlayAttack1()<suspends>:void=
StopLoopingAnims()
MeleeAttackAnim.PlayOneShot().Await()
PlayAttack2()<suspends>:void=
StopLoopingAnims()
MeleeAttackAnim2.PlayOneShot().Await()
PlayAttack3()<suspends>:void=
StopLoopingAnims()
MeleeAttackAnim3.PlayOneShot().Await()
PlayAttack4()<suspends>:void=
StopLoopingAnims()
MeleeAttackAnim4.PlayOneShot().Await()
Generally speaking, it looks like it would work. I assume the indentation being out of alignment is just from pasting it into the replay.
You are correct lol