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.

Problem with having something try to call itself. -SOLVED-

-PROBLEM SOLVED- no further help needed.



Hey, I've got a script that when a file isn't found, instead of throwing an error and closing, it looks in another location, where the file definitely is, and moves the file to where it should be (I'm using this script to sort through my database, so I don't have a ~4gb game.)

The script works perfectly the first time an item isn't found, but after that it seems to not work, probably because the error method is calling itself, and that can't happen.

Anyway. This is used in conjunction with FileUtils.RB, a normal ruby method. This replaces the error handler in the main class.

Code:
rescue Errno::ENOENT
  # Supplement Errno::ENOENT exception
  # If unable to open file, display message and end
  p $!.to_s
  filename = $!.message.sub("No such file or directory - ", "")
  $dest = "D:/Project3/" + filename
  slashes = $dest.count "/"
  loop do # Truncates the end of the string at the slash
    $dest = $dest.chop
    slashe = $dest.count "/"
    if slashes != slashe
      $dest = $dest + "/"
      break
    end
  end
  t = 0
  loop do  #This loop affixes the extension to the file, checking which extension is proper.
    newfileloc = "D:/Project3/2/" + filename
    t +=1
    case t
    when 1
     newfileloc += ".mp3"
    when 2
      newfileloc += ".wav"
    when 3
      newfileloc += ".ogg"
    when 4
      newfileloc += ".mid"
    when 5
      newfileloc += ".jpg"
    when 6
      newfileloc += ".png"
    when 7
      newfileloc += ".bmp"
    end
    if FileTest.exist?( newfileloc ) == true
      FileUtils.mv(newfileloc, $dest)
      break
     else
    end
  end
  while $scene != nil
    $scene.main
  end
end


The code works perfectly the first time each time the game is ran, how can I have it work multiple times each run?
 
You should try this
Code:
class Main
  
  def update
    # Your main method here!
  end
  
end

$main = Main.new

while $main != nil
  $main.update
  break if $scene.nil?
end
Substitute all the code in Main with this. It worked, despite the odd look of this script lol ^^ Just note that it will not close the game unless you put $main or $scene as nil.

Well, was the only thing i could think for now... ^^
 

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