|
drgsldr69 wrote: an example
First, your textbook should show you all of this. Second I cannot fix your code because it does not make any sense. I do not know what "dice" is or "BaseClass". But
public void Character(int Str)
{
string N;
Console.Write("\n");
Console.Write("Your Name is: {0} \n", N);
ShowAbilities(Str);
}
public void ShowAbilities(int Str)
{
Console.WriteLine("Strength: {0}\n", Str);
}
public void RollStr()
{
int Str;
Str = dice.Roll5D6();
Console.Write("Str: {0} \n", Str);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollStr();
}
Character(Str);
}
should be enough to show you how to pass a variable from you RollStr method to your Character method and then to your ShowAbilites method. How you think you will do this in your real application is beyond me as you have not defined what your classes are or how they relate to each other.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Wes Aday wrote: ShowAbilities(Str);
On this part here in bold it doesn't want to accept that because it doesn't see ShowAbilities in that function. Which is why i have the Abilities abilities = new Abilities(); in and abilities.ShowAbilities(Str, etc) which it doesn't want to read right. I did edit my second or third post above this one with the ENTIRE ability class. The only class I didn't paste in this thread now is my dice class which is just to give random numbers between 1 and 6 to the ability score. but I also have other dice in there which ain't being used as of yet.
|
|
|
|
|
See if this makes any more sense. I did not compile this as I cannot. But should get you closer. Pay attention to the comments.
class Abilities
{
private int Str;
private int Intelligence;
private int Dexterity;
Dice dice = new Dice();
public void ShowAbilities()
{
Console.WriteLine("Strength: {0}\n", Str);
Console.WriteLine(string.Format("Dexterity: {0}\n", Dexterity));
Console.WriteLine("Intelligence: {0}\n", Intelligence);
}
public void RollAbilities()
{
Abilities BaseClass = new Abilities();
BaseClass.RollStr();
BaseClass.RollDex();
BaseClass.RollCon();
BaseClass.RollInt();
BaseClass.RollWis();
BaseClass.RollCha();
}
public void RollStr()
{
Abilities BaseClass = new Abilities();
Str = dice.Roll5D6();
Console.Write("Str: {0} \n", Str);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollStr();
}
}
public void RollDex()
{
Abilities BaseClass = new Abilities();
Dexterity = dice.Roll5D6();
Console.Write("Dex: {0} \n", Dex);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollDex();
}
}
public void RollCon()
{
Abilities BaseClass = new Abilities();
int Con;
Con = dice.Roll5D6();
Console.Write("Con: {0} \n", Con);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollCon();
}
}
public void RollInt()
{
Abilities BaseClass = new Abilities();
Intelligence = dice.Roll5D6();
Console.Write("Int: {0} \n", Int);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollInt();
}
}
public void RollWis()
{
Abilities BaseClass = new Abilities();
int Wis;
Wis = dice.Roll5D6();
Console.Write("Wis: {0} \n", Wis);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollWis();
}
}
public void RollCha()
{
Abilities BaseClass = new Abilities();
int Cha;
Cha = dice.Roll5D6();
Console.Write("Cha: {0} \n", Cha);
char MyChoice;
string MyInput;
char ReRoll = Convert.ToChar("y");
Console.Write("Would you like to reroll this score?");
MyInput = Console.ReadLine();
MyChoice = Convert.ToChar(MyInput);
if (MyInput == Convert.ToString(ReRoll))
{
BaseClass.RollCha();
}
}
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Thanks that basically worked I just need to call the function to roll the ability scores first I guess since right now it is showing them as all 0 lol but at least it is printing them.
|
|
|
|
|
Ok I take that back even running RollAbility() first didn't populate the ability scores. Or should I say didn't save them and pass them.It rolls the dice perfectly re-rolls, them great,but still shows each score at 0 when you run the ShowAbilities()
|
|
|
|
|
Your additional problem is probably:
public void RollAbilities()
{
Abilities BaseClass = new Abilities();
BaseClass.RollStr();
BaseClass.RollDex();
BaseClass.RollCon();
BaseClass.RollInt();
BaseClass.RollWis();
BaseClass.RollCha();
}
You are creating a new instance of Abilities, rolling your dice and then your instance goes out of scope so you get nothing. Change that to
public void RollAbilities()
{
RollStr();
RollDex();
RollCon();
RollInt();
RollWis();
RollCha();
}
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Ok this is solved now. Granted I am having other problems but that would be for a different thread lol
|
|
|
|
|
I think Wes has effectively answered your questions.
But, a word of advice, it's good to make clear that what you are passing in this case to a function is not a "variable" but the value (in this case a string) contained inside that variable.
When you are ready, you should examine the keywords 'ref, and 'out to understand the possibilities of what may happen when you want a change to a passed in value within some function to affect the variable that was the source of the parameter in the function.
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
Thanks everyone that has helped. This is part of a character generator for a D&D type game. I'm just hoping I get it in right I have a couple hours before I have to turn it in so wish me luck lol. If I run into any other problems I will be sure to come back.
|
|
|
|
|
How to add new connection string to the application on deployment of application on any other system using setup ?
Shashank Sagar
|
|
|
|
|
Why "during setup"? Your app can determine where it is installed once it's installed; simply ask the current assembly for it's location. You can then dynamically build a correct connectionstring, based on the circumstances;
Will you be installing Sql Server Express? Will the database be auto-attaching, or always attached under a alias? It'd be preferably to name the instance, if it's not shared; and depending on your security-settings, you might be using Windows authentication or Sql Server authentication.
How the connection-string will ultimately look varies per database; you can find examples here[^].
..and what does it have to do with C#?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
hi you can use web.config file it will much better
|
|
|
|
|
that is for websites not for windows application.
Shashank Sagar
|
|
|
|
|
|
Hi guys. I am trying to download images from websites. I found lots of sample codes but they simply implement System.Drawing. I dont have such a header file to implement. Does any one know what happend to my "System.Drawing" header file. I am using visual studio 2010 and C# language.
all the best
|
|
|
|
|
I'm not sure what you mean by "header file" here but you may like to look at the documentation for System.Drawing Namespaces[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
C# doesn't have header-files, you're confused with C. Add the reference to the assembly, and you're good to go. Open the IDE, go to the solution explorer, right-click the "references" node, click "add reference".
System.Drawing is added automagically for WinForms, not Console-applications.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks. As you said I drawing will only apear in windows form applications. Thanks for your help
|
|
|
|
|
I posted earlier about converting a textbox into textarea. Another problem arose when I switched from a listbox to a textbox. I have many buttons each representing a character and when I click on the button I want the text to be added to the textbox. With a listbox the following did the trick: listbox1.Items.Add("あ");
but the same wont work for a textbox. I want to be able to construct sentences with buttons and then be able to copy and paste. Thanks in advance.
modified 26-Aug-12 13:40pm.
|
|
|
|
|
Try:
myTextBox.Text += "A";
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Worked! Thanks a million.
|
|
|
|
|
You're welcome - does that answer your other question as well?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
It certainly does ! Should I remove the other one?
|
|
|
|
|
You can't once there is a reply - don't worry about it.
It would be polite to edit them, and add "[SOLVED]" to the subject line though!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thanks for the info. Still getting the hang of things lol.
|
|
|
|