Sorry If my code is a bit of a mess, I tried to cut out all the unimportant stuff, so there may be some bits missing... my issue is that I am trying to pass the Boolean "CorrectLetter1" into the Game class, if this Boolean is true then the Integer "GatesCleared" Should increase, there are no errors, until I play my game at which point it crashes and gives the error message "Object reference not set to an instance of an object" how do I fix this...
(I am using SFML in C# so my code will be a little different, but I can try and translate from C++)
here is some of my code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using SFML.Window;
using SFML.Graphics;
using System.Drawing;
namespace SFML_Template
{
public class Game
{
Player player;
public int GatesCleared = 0;
public void Update(RenderWindow window, float delta)
{
this.delta = delta;
player.Update(delta);
{
if (GatesCleared == 0)
{
if (player.Position.X >= background.Position.X + 1045)
{
player.Position = new Vector2f(player.Position.X - 2, player.Position.Y);
View view = window.GetView();
view.Move(new Vector2f(-2, 0));
window.SetView(view);
}
}
if (GatesCleared == 1)
{
if (player.Position.X >= background.Position.X + 1045 & player.Position.Y >= player.Position.Y + 440)
{
player.Position = new Vector2f(player.Position.X - 2, player.Position.Y);
View view = window.GetView();
view.Move(new Vector2f(-2, 0));
window.SetView(view);
}
}
if (player.Position.X >= background.Position.X + 900 & player.Position.Y >= background.Position.Y + 100 & player.Position.Y <= background.Position.Y + 150 & GatesCleared == 0)
{
EncryptionActive = true;
if (Encryption.correctLetter1 = true) //Error occurs here
{
GatesCleared += 1;
}
}
else EncryptionActive = false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using SFML.Window;
using SFML.Graphics;
using System.Drawing;
using System.Timers;
namespace SFML_Template
{
public class Encryption : Sprite
{
int letterCount = 1;
Game game;
public Boolean correctLetter1 = false;
public void Update(RenderWindow windowEncypt, float delta)
{
this.delta = delta;
if (letterCount == 1)
{
keyPress = false;
Letter1.Update(delta);
if (Keyboard.IsKeyPressed(Keyboard.Key.Q) || Keyboard.IsKeyPressed(Keyboard.Key.W) || Keyboard.IsKeyPressed(Keyboard.Key.E) || Keyboard.IsKeyPressed(Keyboard.Key.R) || Keyboard.IsKeyPressed(Keyboard.Key.T) || Keyboard.IsKeyPressed(Keyboard.Key.Y) || Keyboard.IsKeyPressed(Keyboard.Key.U) || Keyboard.IsKeyPressed(Keyboard.Key.I) || Keyboard.IsKeyPressed(Keyboard.Key.O) || Keyboard.IsKeyPressed(Keyboard.Key.A) || Keyboard.IsKeyPressed(Keyboard.Key.S) || Keyboard.IsKeyPressed(Keyboard.Key.D) || Keyboard.IsKeyPressed(Keyboard.Key.F) || Keyboard.IsKeyPressed(Keyboard.Key.G) || Keyboard.IsKeyPressed(Keyboard.Key.H) || Keyboard.IsKeyPressed(Keyboard.Key.J) || Keyboard.IsKeyPressed(Keyboard.Key.K) || Keyboard.IsKeyPressed(Keyboard.Key.L) || Keyboard.IsKeyPressed(Keyboard.Key.Z) || Keyboard.IsKeyPressed(Keyboard.Key.X) || Keyboard.IsKeyPressed(Keyboard.Key.C) || Keyboard.IsKeyPressed(Keyboard.Key.V) || Keyboard.IsKeyPressed(Keyboard.Key.B) || Keyboard.IsKeyPressed(Keyboard.Key.N) || Keyboard.IsKeyPressed(Keyboard.Key.M))
{
if (Keyboard.IsKeyPressed(Keyboard.Key.S))
{
correctLetter1 = true;
}
}
}