Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

look for items in icon folder

is there a way you can find all the items in a folder? im asking because im working on my interactive world map script(editor) and that would help me so much!

im trying to make it so you can click a left or right button to cycle through all the possible icons for the town graphic atm.
 
Code:
dir = 'Graphics/Icons/'

# Get all Files in that directory

all_files = Dir.glob(dir + '*')

# Get only the PNG files

pngs = Dir.glob(dir + '*.png')

This method does not work, when the folder is encrypted to the Game.rgssad!

If you don't know, the * means "everything".
 
ok so i finally looked at the code(forgot about this till i needed the code) and i cant get it to give me any useful info i can use. this sets the directory yes? i need to be able to pull all the graphics and draw them to the screen. any advice?


edit: after googleing it, i found zeriabs old page, and this solution:
[rgss]@files = Dir["Graphics/Icons/Towns/*"]
@files.each {|s| s.gsub!(/\.[^\.]*$|[^\/]*\//) {|str| ""}}
[/rgss]

its what im gonna use for now, but if you have any comments on this let me know
 
Code:
@files = Dir.glob('Graphics/Icons/Towns/*').find_all do |f| 

 ext = File.extname(f)

 ext == '.png' or ext == '.jpg' or ext == '.bmp' or ext == '.jpeg'

end

@bitmaps = @files.collect {|i| Bitmap.new(i)}

This should give you an Array of the filenames and an Array of the Bitmaps. But since you already solved it, I guess it doesnt matter.
 
I guess that you're trying to get rid of the file extension. If so, this is the easiest way to do it. It's pretty similar to the one you proposed, Plague.

[rgss]@files = Dir["Graphics/Icons/Towns/*"]
@files.each {|s| s.gsub!(/\.[\w]+/, '')
[/rgss]
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top