C
C#•10mo ago
lelewithheart

Music in my wpf project?

This code is by chatGPT, bc I don't know how to do it. but rider doesn't seem to recognise the 'player' variable. Also I get a unexpected Token error
No description
7 Replies
leowest
leowest•10mo ago
well yeah you're trying to access a method inside a class and outside a method I suggest u take a look at this tutorial https://learn.microsoft.com/en-us/shows/csharp-fundamentals-for-absolute-beginners/understanding-scope-and-accessibility-modifiers so you can understand better about scope so yeah there is no point using ChatGPT if u dont understand the language itself as u wont be able to tell right from wrong or sometimes where to place things u should start with the basics and then move from there
lelewithheart
lelewithheartOP•10mo ago
I do know C#, I have coded the game already, but I have no Idea how to use the media lib
leowest
leowest•10mo ago
well the error is not about how to use the library is clearly about basic knowledge This is what you're doing wrong right now
public class Something
{
static string musicFilePath = "somet path.mp3";
SoundPlayer player = new SoundPlayer(musicFilePath);

// wrong u cannot call this here, you're in the wrong scope
player.Play();
}
public class Something
{
static string musicFilePath = "somet path.mp3";
SoundPlayer player = new SoundPlayer(musicFilePath);

// wrong u cannot call this here, you're in the wrong scope
player.Play();
}
so I pointed u to a guide that explains how scope and variables work
lelewithheart
lelewithheartOP•10mo ago
ohh okay, I'll look into it. Sorry for talking before thinking haha
leowest
leowest•10mo ago
its all good 🙂 and sorry if I sounded rude pointing things directly beyond that are you using winform, wpf or console app?
Sir Rufo
Sir Rufo•10mo ago
I guess WPF because OP asked "Music in my wpf project?" 😉
leowest
leowest•10mo ago
indeed missed the title, thx
Want results from more Discord servers?
Add your server