Help Load & RW Xml

I know it’s not clear I have the impression that the information is there but I can’t process it :frowning: :frowning:

everything is there but I’m missing something

for example if I have a score of 10 and I have a collision it will save 10 in xml then it will display 10 as highscore even if I did 20 the old part

First of all, your English is fine, I don’t know what your native language is, but I will bet 100% your English is WAY better than my knowledge of your native language :slight_smile:

You could be making a number of mistakes here,

Before going to the game over screen, you are not storing the new score in the list of scores, so the new score is not added to the list and so does not get shown.

Ideally, you should load the list from xml when the game starts, use and update this list in your screens untill the user closes the game, at which point you then save the list back to the xml file.

I think you have got the serialization and rendering OK, you need to understand how you have implemented your game state/screens.

1 Like


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

thanks in advance

The method?

Hello :smiley:
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 ...

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


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


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"))

        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