C
C#•2d ago
Silk&Song

Why is it still 2?

Why is totaldamageYou still 2?
38 Replies
ero
ero•2d ago
why is what still 2
Silk&Song
Silk&SongOP•2d ago
mb
Silk&Song
Silk&SongOP•2d ago
Silk&Song
Silk&SongOP•2d ago
this is paused before the enemy dmg caculation also
Silk&Song
Silk&SongOP•2d ago
Keswiik
Keswiik•2d ago
$code
MODiX
MODiX•2d ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Keswiik
Keswiik•2d ago
most people don't want to download random files
Silk&Song
Silk&SongOP•2d ago
BlazeBin - ophphrqiiuor
A tool for sharing your source code with the world!
Keswiik
Keswiik•2d ago
ty, will take a look at it once I'm at my pc
Silk&Song
Silk&SongOP•2d ago
k
Silk&Song
Silk&SongOP•2d ago
BlazeBin - lsaovwqzoplo
A tool for sharing your source code with the world!
Silk&Song
Silk&SongOP•2d ago
um guys i think i just fixed it hold on leme see nvm
Pope
Pope•2d ago
can you give Player code?
Silk&Song
Silk&SongOP•2d ago
yes
Silk&Song
Silk&SongOP•2d ago
BlazeBin - fkirmdmgwxdy
A tool for sharing your source code with the world!
Pope
Pope•2d ago
I started to look at it: https://paste.mod.gg/smksixlurjhq/0 I took out all of the ReadKey because we're just at the debugging stage, right? Easy enough to add them in later.
Silk&Song
Silk&SongOP•2d ago
I think i might have fixed it but sometimes it works and sometimes it dosent
Pope
Pope•2d ago
I don't know what the problem is. I was just kind of refactoring the code to something that's quick/easy to test. what are the inputs necessary to get to the point you want?
Silk&Song
Silk&SongOP•2d ago
for instance if you defend and then the enemy defends if u attack the next turn and the enemy attacks the next turn it will work and damage will = 1 but if you start the battle and defend and they attack right after it dosent work. damage will = 2 (totaldamageYou)
Pope
Pope•2d ago
oh, I don't think I saw that code.
Silk&Song
Silk&SongOP•2d ago
No I mean the inputs that will sometimes get it to work and the inputs that dont
Pope
Pope•2d ago
https://paste.mod.gg/czdicnpqwdnz/0 I thought this was the full code. So I didn't have anything related to fighting.
Silk&Song
Silk&SongOP•2d ago
heres what happens if they attack right after
Pope
Pope•2d ago
You can see what I'm doing with your code. I'm separating out all of the text and inputs so I can quickly test for some known inputs
Silk&Song
Silk&SongOP•2d ago
Pope
Pope•2d ago
Yeah, that just has player code.
Silk&Song
Silk&SongOP•2d ago
this one here has it
Pope
Pope•2d ago
Yeah, I spent time on the wrong one. Hopefully someone else can help you more. You'd still benefit from breaking out all of the Console stuff from your main code
Silk&Song
Silk&SongOP•2d ago
Ok i will @yolan Heres my problem: In my code this code
int ArmourPlusArmour1 = 0;
ArmourPlusArmour1 += Program.currentPlayer.armourValue + Program.currentPlayer.temparmourValue;
int totalDamageYou = d - ArmourPlusArmour1;
Console.ForegroundColor = ConsoleColor.DarkBlue;
int ArmourPlusArmour1 = 0;
ArmourPlusArmour1 += Program.currentPlayer.armourValue + Program.currentPlayer.temparmourValue;
int totalDamageYou = d - ArmourPlusArmour1;
Console.ForegroundColor = ConsoleColor.DarkBlue;
it caculates the damage based on the temp armour and armour. Now in my code i have a defend button and when you press it it increases tempArmour by 1.
else if (input.ToLower() == "d")
{
Console.ForegroundColor = ConsoleColor.Blue;
Program.typingEffect($"You steel yourself for any attack. ", 10);
Program.currentPlayer.temparmourValue++;
if (Program.currentPlayer.temparmourValue > 1)
{
Program.currentPlayer.temparmourValue = 1;
}
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");


Console.ReadKey();
else if (input.ToLower() == "d")
{
Console.ForegroundColor = ConsoleColor.Blue;
Program.typingEffect($"You steel yourself for any attack. ", 10);
Program.currentPlayer.temparmourValue++;
if (Program.currentPlayer.temparmourValue > 1)
{
Program.currentPlayer.temparmourValue = 1;
}
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");


Console.ReadKey();
Now when the enemy attacks
Console.WriteLine("--Enemy Turn--");
if (Program.currentPlayer.temparmourValue <= 0)
{
Program.currentPlayer.temparmourValue = 0;
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");
}
int EnemyChoice = random1.Next(2, 6);

if (EnemyChoice == 2 || EnemyChoice == 3)
{

Program.typingEffect($"The {n} swings its crude axe with ferocity, dealing {totalDamageYou} damage as the blade connects!", 10);

Program.currentPlayer.Health -= totalDamageYou;
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");

if (Program.currentPlayer.temparmourValue < 1)
{
Program.currentPlayer.temparmourValue = 0;
}
Program.currentPlayer.temparmourValue--;
Console.ReadKey();
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");
Console.WriteLine("--Enemy Turn--");
if (Program.currentPlayer.temparmourValue <= 0)
{
Program.currentPlayer.temparmourValue = 0;
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");
}
int EnemyChoice = random1.Next(2, 6);

if (EnemyChoice == 2 || EnemyChoice == 3)
{

Program.typingEffect($"The {n} swings its crude axe with ferocity, dealing {totalDamageYou} damage as the blade connects!", 10);

Program.currentPlayer.Health -= totalDamageYou;
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");

if (Program.currentPlayer.temparmourValue < 1)
{
Program.currentPlayer.temparmourValue = 0;
}
Program.currentPlayer.temparmourValue--;
Console.ReadKey();
Console.WriteLine($"d: {d}, armourValue: {Program.currentPlayer.armourValue}, temparmourValue: {Program.currentPlayer.temparmourValue}");
}its suppose to decrease damage by 1. It dosent. The temparmourValue will BE = TO 1 and still ArmourPlusArmour1 will be 0. It dosent make sense. Heres another thing, When defending right when the battle stars and the enemy attacks right after the damae will still be 2. But if you defend and enemy also defends.Next turn when the enemy attacks damage will be = to 1 . I will provide you with an shrot video
Silk&Song
Silk&SongOP•2d ago
Silk&Song
Silk&SongOP•2d ago
battle code.
Silk&Song
Silk&SongOP•2d ago
Silk&Song
Silk&SongOP•2d ago
(both defend and both attacked causing it to work) dosent matter when it starts aslong as its in order also and heres the player code
yolan
yolan•2d ago
well ... such error are often created when there is a var not in the proper scope "bracket symbols"... else than that you should make sure you Log your error only at the end of everything not in the middle since you do tons of math it will get confusing finding the error.... for me your code is so simple that it is not a bug , it behave like it should ... there is also the possibility of you erasing a variable with the "=" operator ! at your place i would try to make the code more clear and take time to read every line ! ... some time just sleeping on it and coming back in the morning ; you get to see more clearly but thats my take on it ! 🙂 peace to you good luck
Silk&Song
Silk&SongOP•2d ago
i made it a field tho in a minute imma just leave it there @Pope I.... Fixed it sorry for pinging you wasnt thinking when i did that I fixed it . The problem was: At the start the caculation totalDamage get scaculated then if you defend it tempArmour gets ++ right. But the cacutaltions only happens when the loop resets. so when the enemy attacked it still did 2 damage because the caculation wasnt updated So i added checks in the middle so that fixed it after 2 days its finally fixed 😄 Thank you all
Mąż Zuzanny Harmider Szczęście
$close @Silk&Song
MODiX
MODiX•6h ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?