Hello DaniWeb community! I recently posted a question asking about the character creation screen and that it is all set! I then continued with form validation, and storing values and spitting them back out in a message box. Then I made the create a character screen close, and open the home screen, which is a bigger window with a different UI and functions. But if I got, say, the gender:

if (rdoMale.Checked)
                player1.Gender = "Male";
            else
                player1.Gender = "Female";

And I go to my new form creation, I noticed that I cannot call player1 from my previous code Player player1 = new Player(); where Player is my main player entity. The entity sets everything to 0 and " ". I also saw that if I call player1.gender on my new form it would not work, so I would have to call Player player1 = new Player();which I believe would set my variables I just got, back to 0.

Is there a way I could store the variables from the character creation screen, then call them after I closed the window? Would it have to be written to a text file? Or could I make another class with it.

Any help is appreciated,
Kyle

Every time you call Player player1 = new Player(); you get the default values for player1. So if you set the properties for player1 like gender etc. and and you call Player player1 = new Player(); again in another form(as I understood it that is) you just get a "new" player1 with his default settings.

Every time you call Player player1 = new Player(); you get the default values for player1. So if you set the properties for player1 like gender etc. and and you call Player player1 = new Player(); again in another form(as I understood it that is) you just get a "new" player1 with his default settings.

I understand that part. How I have organized my solution is to have an Engine.cs be a class library and have it linked as a reference to KylesRpgGame, which is what is making the game run. I have the default values set as 0 in the Engine, and I am setting them using the character creation. But when I call the Player player1 = new Player(); I am setting the variables back to 0, and I do not intend to. I would like to keep the variables from the first form, and transfer it to the second form, and I am having a hard time doing that.

You could set up e.g. a List<Player> field in the second form. All you have to do is fill up that list from the first form.

I'm not a C<anything> enthusiast, but this sounds like a generic architecture question, and here's the standard generic answer.

Normally you would have a "game" class that contains (or knows about) all of the data and state information for your game. It has no user interface, but does have public methods to get/set/add its data and state info. You create an instance of it when the game starts.
Whenever you open a new window you pass the game instance to it (eg as a parameter to the window's constructor). The window then can access whatever data it needs, and pass any updates or new data back to the game instance.
In your case, the first form will pass its new Player back to the game instance, and the second form will query the game instance to get the Players.
(Inside the game instance you could indeed use something like a List<Player> to maintain all the player info)

commented: I know you're into Java, but definitely in OO also! +15

It did not work, I am having a hard time getting the variables from the first form. Form1 sets all the variables from the class library "Player". In my first form I set Player player1 = new Player(); to get all the default varibles from "Player" which I set everything to 0. On form2 I want to keep all the variables from form1, but I do not know how to set up from2 to inherit all of the varibles from form1. I thought since they were public, and I set all varibles in "player" to {get; set;} that all the varibles would be stored on "player".

Maybe I am not doing the list right?

Follow the advice of JamesCherill.
And I would have one main form with a button "Start game" to summon an instance of the game class.
Also have other button on your main form like "Manage player" (or something like that) which could call a player edit dialog form to manage this list of players in the game class. How to set up such dialog correctly you can find out in this daniweb snippet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.