I have a project that is divided into 3 seperate visual studio projects, a Game, Console and Library project, I am trying to get a static variable from the library to change from my console project and then read it in the game project. Here is some code to clear that up:
This is my library code, my one variable I want to change
namespace LibraryProject.Values
{
public class Variables
{
public static string LastSaid { get; set; }
}
}
This is the console project, where I change this string in the library project:
namespace ConsoleProject
{
private void Client_OnMessageRecieved(object sender, OnMessageReceivedArgs e)
{
Console.WriteLine("Recieved message, the message was: " + e.ChatMessage.Message);
Variables.LastSaid = e.ChatMessage.Message;
Console.WriteLine("LastSaid is now: " + Variables.LastSaid);
}
}
and finally this is my gameproject, that shows the value on the screen.
namespace LibraryProject
{
public Interface(ContentManager content)
{
TextString lastSaid;
public void Update()
{
lastSaid = new TextString(fonts.Font1, Variables.LastSaid, new Vector2(100, 100), Color.White);
}
}
My TextString class:
namespace LibraryProject
{
class TextString
{
SpriteFont Font;
string Text;
Vector2 Position;
Color Color;
public TextString(SpriteFont font, string text, Vector2 position, Color color)
{
this.Font = font;
this.Text = text;
this.Position = position;
this.Color = color;
}
public void Draw(SpriteBatch spriteBatch)
{
if (Text != null)
{
spriteBatch.DrawString(Font, Text, Position, Color);
}
}
}
}
My game project:
namespace GameProject
{
public class GameCore : Game
{
protected override void LoadContent()
{
Interface = new Interface(Content);
}
protected override void Update()
{
Interface.Update(gameTime);
}
}
}
I can change the value in the Console project just fine, my console outputs that the LastSaid variable in the library project has changed, but when I finally want to output the LastSaid variable in my game project, it does not change at all when I check up on the variable, it stays at the value it was instanced at. Can someone help me explain why this happens?