Click here to Skip to main content
15,069,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am receiving this error:
error CS0103: The name 'Methods' does not exist in the current context

My code:
C#
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SwordsMod.NPCs.Bosses
{
    public class Optime : ModNPC
    {
        int attackTimer = 0;
        int spread1timer = 150;
        int spread2timer = 151;
        int rapid1timer = 151;
        int rapid2timer = 151;

        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("O P T I M E");
            Main.npcFrameCount[npc.type] = Main.npcFrameCount[3];
        }

        public override void SetDefaults()
        {
            npc.width = 78;
            npc.height = 104;
            npc.damage = 999999;
            npc.defense = 8;
            npc.HitSound = SoundID.NPCHit1;
            npc.DeathSound = SoundID.NPCDeath1;
            npc.value = 0f;
            npc.knockBackResist = 0f;
            npc.aiStyle = -1;
            animationType = -1;
            npc.boss = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.aiStyle = -1;
            npc.lifeMax = Main.expertMode ? 3000 : 5000;

        }
        int useJitterMethod = 1; //set this to 1 for method 1 set it to 2 for method 2
        //variables used for both methods
        Vector2 moveTo;
        float flyDirection;
        //settings for both methods
        float heightAbovePlayer = 200;
        //variables used for jitter method 1

        //settings for jitter method 1
        float acceleration = .8f; // acceleration rate
        float maxSpeed = 7f; //max speed


        //variables used for jitter method 2
        float currentFlyDirection;
        //settings for jitter method 2
        float speed = 12; //how fast it moves
        float rotationSpeed = 20; //rotation speed in degrees per frame
        public override void AI()
        {
            //look at stuff.cs for information on the SlowRotation and PolarVector
            Player player = Main.player[npc.target];
            npc.TargetClosest(true);
            moveTo = new Vector2(player.Center.X, player.Center.Y - heightAbovePlayer);

            flyDirection = (moveTo - npc.Center).ToRotation();

            if (useJitterMethod == 1)//jitter method 1 Acceleration
            {

                npc.velocity = Methods.PolarVector(acceleration, flyDirection);  
                                                                                       
                if (npc.velocity.Length() > maxSpeed)
                {
                    npc.velocity = npc.velocity.SafeNormalize(-Vector2.UnitY) * maxSpeed;
                }
            }

            if (useJitterMethod == 2) //jitter method 2 slowed direction change
            {


                currentFlyDirection = Methods.SlowRotation(currentFlyDirection, flyDirection, rotationSpeed); 
                npc.velocity = Methods.PolarVector(speed, currentFlyDirection); 

            }

            attackTimer++;
            if (attackTimer == 300)
            {
                switch (Main.rand.Next(1, 5))
                {
                    case 1:
                        {
                            spread1timer = 0;
                            break;
                        }
                    case 2:
                        {
                            spread2timer = 0;
                            break;
                        }
                    case 3:
                        {
                            rapid1timer = 0;
                            break;
                        }
                    case 4:
                        {
                            rapid2timer = 0;
                            break;
                        }
                }
                attackTimer = 0;
            }
            spread1timer++;
            if (spread1timer == 30 || spread1timer == 60 || spread1timer == 90 || spread1timer == 120 || spread1timer == 150)
            {
                for (int i = 0; i < 10; i++)
                {
                    float Speed = 12f;
                    int type = mod.ProjectileType("Happfiier");
                    float rotation = ((((float)Math.PI / 5) * i) + (float)Math.Atan2(npc.Center.Y - 10, npc.Center.X - 10));
                    int proj = Projectile.NewProjectile(npc.Center.X, npc.Center.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, 999999, 0f, 0);
                    Main.projectile[proj].tileCollide = false;
                }
            }
        }
        public override void FindFrame(int frameHeight)
        {
            npc.spriteDirection = 0;
            npc.rotation = 0;
            npc.spriteDirection = npc.direction;
            npc.frameCounter++;
            if (npc.frameCounter >= 8) // ticks per frame
            {
                npc.frame.Y = (npc.frame.Y / frameHeight + 1) % Main.npcFrameCount[npc.type] * 104;
                npc.frameCounter = 0;
            }
        }
    }
}


What I have tried:

I tried capitalization, spelling, and nothing has worked.
Posted
Updated 9-Aug-18 21:58pm
v2

Well, the error message says that you don't have a class called "Methods" anywhere in your project, either in your own code files or in any namespace that you imported in your "using" statements at the top of the code.
   
Comments
Member 13944019 9-Aug-18 14:52pm
   
But how can i fix the error?
Dave Kreskowiak 9-Aug-18 15:29pm
   
So, where did you get this code from?
You are trying to call what look like static methods in the Methods class, but you have not imported a definition of the class via a using directive.
C#
currentFlyDirection = Methods.SlowRotation(currentFlyDirection, flyDirection, rotationSpeed);
npc.velocity = Methods.PolarVector(speed, currentFlyDirection);

Check the documentation for the class.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900