Help Load & RW Xml

Hello,

:smiley:
thank you very much i understand my mistake
i think it’s like you said writing score in xml
I will redo the Menu properly and I will try
what do you think of the method?
enum GameState
{
MainMenu,
Gameplay,
EndOfGame,
GamePlay,
}

thanks in advance

The method?

Hello :smiley:
sorry
it is from this method
Switch scenes in monogame? to create the menu
I tested it works great :slight_smile:

now i put my code in order

the high score works :smiley:

in the event of a collision it returns me to the menu with the best score

on the other hand if I turn off the app
it no longer displays the old score

i have to find the way how to display the old score

do I have to load the score for example in my playGame method?

can you help me thanks in advance

I did this in UpdateGameplay

in loadContent
i use
_scoreManager = ScoreManager.Load(); // load function with read streamer

//add new score
_scoreManager.Add(new Score()
{
PlayerName = “PlayerName”,
Value = score,
}
);

               //save function score with streamwriter ...
                    ScoreManager.Save(_scoreManager);

OK, you are using code from another thread to manage your state, I’m not going to get into that code.

I don’t uderstand what you mean by

on the other hand if I turn off the app
it no longer displays the old score

What old score? If you are loading your serialized score data at start up, then that’s what it should be showing…

1 Like

Hello

for example if I end a game
I close the application

if I restart the application and a new part
the high score is not displayed at startup
as if it does not exist in the xml

carrying the call in the loadContent

how did you go about opening the xml file i can’t find it?
just to see
wearing I know it exists and that I write well in it

Sorry for the inconvenience
thank you

it works perfectly :smiley:

I had a line of code that calls a new scoremanager

thank you very much for everything

Great

1 Like

it works on the virtual device but not on the smartphone :frowning:

is this a history of the file location on the system?

or when it tries to load xml it cannot find it because it is not yet created?

it’s this code if (! File.Exists (_fileName))
returns a new ScoreManager ();

when i removed this code it works in virtual but not in real
does this mean that the file does not exist or because it is not yet created? and these 'for what creates a new void?

if (!Directory.Exists($"{_fileName}/SaveData"))
Directory.CreateDirectory($"{_fileName}/SaveData");

        if (!File.Exists(_fileName))
        return new ScoreManager();

Can you see the difference in what _fileName is on either the virtual or physical? I don’t know why you are having this issue, the method(s) I have described work fine for me both in the emulator and on my S10.

1 Like

thank you for the answer I misspoke after the modification it works in virtual but I can’t install it in physics it tells me there is an installation problem

The application is installed, but at launch it shows me
the application has stopped :frowning:

the launch screen is displayed after the app stops

Are you putting break points in and running it in debug?

in debug it works it is when starting the app that it stops

it’s strange normally it should work since it works on the simulator

is there a way to check in release mode? have the impression that it cannot find the xml file in the physical memory?

So, when you run it from VS on the device, what are you seeing?

when I run on VS everything works perfectly

it shows me the best scores even if I turn off the application