Re: some help needed with python
Re: some help needed with python @12Are you sure that's where the file is located?Also, not sure if it's relevant, but your code (and output) is showing up with a right quotation mark, rather than an apostrophe or double quote. Not sure what editor you're using, but this could be important.For a kick off, I'd suggest using the following code (where filename is the copied filename from your code):import os os.path.isfile(filename)If your path is valid, that code should return True.Also, save yourself a headache, and either use the pathlib module:from pathlib import Path filename = Path('sounds/filename.wav') # Then to maek it astring: str(filename)Or at least using raw strings. You can make them with an r in front:filename = r'sounds\filename.wav'HTH. URL: https://forum.audiogames.net/post/596475/#p596475 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
2020-12-08
Thread
AudioGames . net Forum — Developers room : Samuel Farrugia via Audiogames-reflector
Re: some help needed with python Hello all, apologies for bringing this topic back from the dead, but I’ve run into a fresh, new, and very crappy problem. So, thanks to your guys’ posts, I was able to figure out how to play music. For some strange reason however, playing sounds still remains a problem. If I was to write this piece of code.Menu_Confirm = pygame.mixer.Sound(“Sounds\\UI\\Confirm.wav”)The program gives me the following error.Pygame.error: Unable to open file ’Sounds\\UI\\Confirm.wav’I’ve tried applying the solutions suggested, but to no effect. I’ve searched, and I can’t find any solution which fixes my problem. URL: https://forum.audiogames.net/post/596469/#p596469 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python aggreed with @8you can also use double backslashes. here, i will explain you the logic why it isn't working.as you know, we have many backslash characters in strings like \n or \rso, here you used backslash followed by the name of the audio. python interpreter thinks that the character which is after backslash as a backslash character. and thus, to prevent this, either you use os.path.join or use double backslashes or forward slashes. any way, os.path.join does the same. it joins the path with double backslashes. so, again, use double backslash or one forward slashes.hope this helps URL: https://forum.audiogames.net/post/590208/#p590208 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python aggreed with @8you can also use double backslashes. here, i will explain you the ligc why it isn't working.as you know, we have many backslash characters in strings like \n or \rso, here you used backslash followed by the name of the audio. python interpreter thinks that the character which is after backslash as a backslash character. and thus, to prevent this, either you use os.path.join or use double backslashes or forward slashes. any way, os.path.join does the same. it joins the path with double backslashes. so, again, use double backslash or one forward slashes.hope this helps URL: https://forum.audiogames.net/post/590208/#p590208 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python pygame.mixer.init() is if you're using the rest of pygame. URL: https://forum.audiogames.net/post/589965/#p589965 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python Double your \ so they're escaped, and use os.path.normpath to make sure it's formatted correctly.With pygame, I get confused about when you should use pygame.mixer.init, and when you should use pygame.mixer.pre_init. You do one when you use the rest of pygame, and the other when you use mixer by itself. If you're not using any of pygame, you might not need to call pygame.init.Looking quickly at an example that I know works, I think this is your problem. Either drop pygame.init, or drop pygame.mixer.init, and instead put pygame.mixer.pre_init above pygame.init. URL: https://forum.audiogames.net/post/589958/#p589958 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python hi...from what I know, python treets backslashes as line continuation character, maybe try useing forward slashes instead? URL: https://forum.audiogames.net/post/589953/#p589953 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
2020-11-15
Thread
AudioGames . net Forum — Developers room : Samuel Farrugia via Audiogames-reflector
Re: some help needed with python @6, thanks for the suggestion, I’ve gone and done that. When I tried adding ‘r’ to the file path, a couple of things happened. Firstly, when I tried it with a .wav file, pygame brought me this error.pygame.mixer.music.load(r'A_2093\Sounds\Intros\Survivor\Survivor_Intro_Music.wav')Pygame.Error: couldn’t Open 'A_2093\Sounds\Intros\Survivor\Survivor_Intro_Music.wav'When I gave it a shot with an .mp3 file, it gave me the same error.Is it just that pygame can’t support .wav and mp3 files? Cause I have no clue what the problem could be otherwise. URL: https://forum.audiogames.net/post/589951/#p589951 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python You need to add an r in front of your path string, it needs to look like this: pygame.mixer.music.load(r'A_2093\Sounds\Intros\Survivor\Survivor_Intro_Music.ogg')Otherwise the backslashes won't be properly escaped. Or decide for the regular string and escape them properly:pygame.mixer.music.load('A_2093\\Sounds\\Intros\\Survivor\\Survivor_Intro_Music.ogg') URL: https://forum.audiogames.net/post/589832/#p589832 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python Can you post the full traceback? As for the current working directory, add this to your script:import os print(os.getcwd())This will tell you the current working directory, which is where your script is looking for your files. If your files aren't in the working directory, you can change that directory with os.chdir() before trying to load them. URL: https://forum.audiogames.net/post/589815/#p589815 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
2020-11-14
Thread
AudioGames . net Forum — Developers room : Samuel Farrugia via Audiogames-reflector
Re: some help needed with python Hi all.@3, the reason I decided on trying to use pygame to play my sound files, rather than the playsound module, is that I wanted to loop music in the background, whilst also having other audio files playing at the same time. I’ve tried using playsound, and it worked, but I’m not sure if I can do things such as loop tracks, and other things like that. Though, for all I know I could be talking nonsense, in which case please correct me.@2, I’ve checked on the directory, and changed it to one in my desktop, but the problem is still there. Pygame keeps reporting that it can’t open the file, no matter what format it is.I’ve gone ahead and nuked my old code, replacing it with some new lines, as follows.# import all the needed modulesImport cmdimport textwrapimport commandimport jsonpickleimport osimport randomimport timeimport sysimport pygamefrom random import randintfrom pygame import mixerpygame.init()pygame.mixer.init()pygame.mixer.music.load('A_2093\Sounds\Intros\Survivor\Survivor_Intro_Music.ogg')the current full directory is: C:\Users\Samuel\Desktop\A_2093\Sounds\Intros\Survivor\Survivor_Intro_Music.ogg URL: https://forum.audiogames.net/post/589772/#p589772 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python Why exactly do you need pygame for this? It appears to be a console game. You can try.import playsoundplaysound.playsound("meow.wav",block=True/False) # block is if the thread should be slept or not until the sound is done. URL: https://forum.audiogames.net/post/589272/#p589272 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
Re: some help needed with python
Re: some help needed with python Part of it could be pathing and the current working directory. Try using a simpler test script for loading/playing sound, you can find one [here] in one of my previous posts. If it doesn't work, you can try checking the current working directory. URL: https://forum.audiogames.net/post/589266/#p589266 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
some help needed with python
2020-11-12
Thread
AudioGames . net Forum — Developers room : Samuel Farrugia via Audiogames-reflector
some help needed with python Hello all.I’m trying to code a small text based RPG (in the same style of the Wastes), as my first python project. I’ve been trying to find a way how to implement sounds for when the player selects different options, fights enemies, etc.after a bit of research, I settled on using pygame as my best bet. Now, for what ever reason, when I try to load and play the sound file, it doesn’t work. I’ve placed the sound effect that I’m trying to use (which is a .wave file), right next to the .py file where all my code is, defined a sound object, tried to load it, only for pygame to inform me that it can’t open the wav file. I’ve tried multiple different file formats, including .mp3, and .ogg. I had the same problem with .mp3 files: and with .ogg files, pygame didn’t bring me an error message, the game launched as per normal, but it never played the sound file.I’ve tried looking online, but I found nothing that worked. So if somebody could point out what stupid mistake I am more than likely making, I would highly appreciate that.Now, at last, I present you with the code in question.import pygamefrom random import randintfrom playsound import playsoundfrom pygame import mixerpygame.init()pygame.mixer.init()#setting up all needed VariablesIsCombatKnifeEquipped = FalseIsBulletProofVestEquipped = FalseIsTacticalBatonEquipped = FalseIsIronPipeEquipped = FalseIsCombatHelmetEquipped = FalseIs10mmPistolEquipped = FalseIsSemiautomaticShotgunEquipped = FalseIs10mmPistoleLoaded = TrueIsSemiautomaticShotgunLoaded = True#setting up the playerclass Player(object): def __init__(self, name, health, strength, dexterity, intelligence, charisma, perception, money): self.name = name self.health = health self.strength = strength self.dexterity = dexterity self.intelligence = intelligence self.charisma = charisma self.perception = perception self.money =money#setting up all items#setting up armorclass Armor(object): def __init__(self, name, protection, durability, value): self.name = name self.protection = protection self.durability = durability self.value = valueBulletProofVest = Armor('bullet proof vest', '20', '80', '150')CombatHelmet = Armor('combat helmet', '10', '40', '65')#setting up CQC weaponsclass CQCWeapon(object): def __init__(self, name, damige, durability, value): self.name = name self.damige = damige self.durability = durability self.value = valueCombatKnife = CQCWeapon('combat knife', '10', '20', '15')TacticalBaton = CQCWeapon('tactical baton', '15', '30', '20')IronPipe = CQCWeapon('iron pipe', '4', '10', '4')#setting up gunsclass Gun(object): def __init__(self, name, damage, clipsize, ammotype, durability, value): self.name = name self.damage = damage self.clipsize = clipsize self.ammotype = ammotype self.durability = durability self.value = valuePistol10mm = Gun('10mm pistol', '14', '12', '10mm magazine', '50', '80')SemiautomaticShotgun = Gun(' Semi automatic Shotgun', '25', '4', '12gage shells', '60', '180')#setting up ammunitionclass Ammo(object): def __init__(self, name, value): self.name = name self.value = valuemagazine10mm = Ammo('10mm magazine', '15')ShotgunShells = Ammo('12gage', '30')#mane game#title screen#setting up the options for the title screendef Title_Options(): menu = pygame.mixer.Sound('menu_select.wav') print ("Please select one of the following options") print ("1: start. 2: help. 3: quit.") Title1 = input(" ") if Title1 == "1": menu.play() chargen() elif Title1 == "2": Help_Menu() elif Title1 == "3": print ("thank you for playing") sys.exit while Title1 not in ['1', '2', '3']: print ("Please select one of the valid commands") print ("1:start. 2:help. 3:exit.") Title1 = input(" ") if Title1 == "1": menu.play() chargen() elif Title1 == "2": Help_Menu() elif Title1 == "3": sys.exit print ("thank you for playing") URL: https://forum.audiogames.net/post/589234/#p589234 -- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector