how do you reference images, sounds, folders, and other such files located in folders on a repl?
how do you reference images, sounds, folders, and other such files located in folders on a repl?
how do you reference images, sounds, folders, and other such files located in folders on a repl?
You would do it the same way you would do it if the files were in your file system. But it depends on the programming language you are using, which you did not specify. For example:
If I was using JavaScript, Html, and Css, and I had an image, 'carrot.png,' inside a folder called 'images,' then I could reference it, assuming my file is in the same directory as the folder, by typing this: images/carrot.png.
however, if I was using python, and trying to open a file, I would do it differently. Say I have a text file, 'words.txt,' and it is inside a folder called 'textFiles,' to open the file in python I would do this: fin = open('textFiles/words.txt')
Hope that makes sense and answers your question!
@Nemoiscool The language was Python; I'm so sorry I forgot to include that in my question, but even without it, you did an absolutely outstanding job answering and explaining in detail exactly how to do what I was asking!
That was a perfect explanation that completely answered my question! Thank you so much!! I have marked your response as the question's official answer and upvoted your response. Thanks again!!
@Nemoiscool Although, I am using PyGame, so would it still be the same thing? I transferred over code from a project I made on the Python IDE Program on a Windows Computer originally so what would I change these type of things to? (Unless it would be the same thing)...
@NY_ISLANDER_FAN Ah, pygame is a bit different then python, normally in python you can't display images, so I decided to just explain how to use a text file.
I see that you are using pygame.image.load(), Which should be correct, and I see you're joining the variable img_folder and the image. Assuming img_folder is a string, and it is the correct spelling for the folder, there is only one thing I can see that might be wrong, although I can't test to find out for sure.
To explain, I'm going to assume the folder is called 'images', and that you've set img_folder = 'images' so that when you use it it goes into the correct folder to find the image. Doing path.join(img_folder,'powerupBlue_shield.png') then joins the strings together to create 'imagespowerupBlue_shield.png,' which is a file that I immediately assume doesn't exist.
My suggestion:
on the parts that say path.join(img_folder,'whateverImageName')
do this instead:
path.join(img_folder,'/whateverImageName')
This way, joining 'images' and /powerupBlue_shield.png returns 'images/powerupBlue_shield.png'
I am not sure if that is the problem, but I hope that helps!
@Nemoiscool Thanks for responding so quickly!
So at the beginning, I have this:
@NY_ISLANDER_FAN I believe I was correct about the issue, every time you join a folder with anything, make sure the '/' character is in between them.
@NY_ISLANDER_FAN @Nemoiscool And these are the current File Folders I have, (everything's in them that I referenced, but I didn't want to expand the folders because then the list of files is literally like miles long and it would've been unnecessary.
@NY_ISLANDER_FAN Yeah, No problem, I don't need to see every file.
@Nemoiscool So I did that, and ended up getting an error;
Although it only references the first one in the error, I presume the same thing would happen for all of them due to the fact that Python just runs in order so it caught that one first, threw the error, and then broke the program.
@NY_ISLANDER_FAN interesting... Try just typing in the file path instead of using the path.join().
@Nemoiscool How do I only reference the file path in repl.it though —— instead of using that method...?
@NY_ISLANDER_FAN just type pygame.image.load('Images/whateverImage')