1

I am programming a boss fight using tModLoader for Terraria, and I am having issues. 1. The section commented as "// Run one of 4 normal attacks" is not running at all. (Okay, well, it might be, but at least the Main.NewText() sections aren't working.) 2. The random.Next() is returning 0.

I don't know if this question has been asked before (it wasn't in the list of suggestions you get when you begin to ask a question), so anything you can do is good. (My main issue is #1)

For #1 I have tried switching around the positions of the forloops and the if statements. This is all I can think of to do, unfortunately. For #2 I cannot see what is wrong, and I haven't tried anything.

Code here: https://pastebin.com/yxe7XP8G (This bit here is what I think is the most likely explanation for this)

        public override bool PreAI()
        {
            if (npc.ai[0] == 0)
            {
                Main.NewText("The power of sock fetishes overwhelms you...", 224, 147, 4, true);
                npc.ai[0] = 1;
            }
            int hazumekAttackConj = 0;
            int hazumekAttackIDCurrent = 0;

            npc.TargetClosest(true);
            Player player = Main.player[npc.target];

            Random random = new Random();
            // Run one of 4 normal attacks
            Main.NewText(hazumekAttackIDCurrent);

I don't know what exactly is breaking here, so I will share my entire PreAI() hook.

No error messages are displaying.

I expect the chat output to be: "Hazumek NRM Attack 1-4", then "Hazumek CNJ Attack S1" Then, "Hazumek NRM Attack 1-4", then "Hazumek CNJ Attack S2". This should repeat forever.

The chat output is actually "Hazumek CNJ Attack S1" and then "Hazumek CNJ Attack S2" over and over again.

  • Not an answer to your question, but if you are using this in a loop, be aware of [random returning the same value](https://stackoverflow.com/questions/767999/random-number-generator-only-generating-one-random-number) in situations where it was created multiple times in a tight loop. Anyway, I don't see how it can return 0 since you're calling `random.Next(1,5);` - **this code is important and should be part of your question and not an off-site link!**. You'll have to step through your code with the debugger. – ProgrammingLlama Sep 05 '19 at 02:06
  • I am such an idiot, I had hazumekAttackIDCurrent set to 0, having it change at a point which the code can never reach. I'll see if this works – InsertUsernameSTO Sep 05 '19 at 02:35
  • Alright, I'm going to totally rewrite the code. I'm out of options – InsertUsernameSTO Sep 05 '19 at 04:02

0 Answers0