Help with deleting bitmaps

Status
Not open for further replies.

Killer_Van

Stupid Person
Member
Joined
Jul 19, 2018
Messages
20
Reaction score
2
First Language
italian
Primarily Uses
RMVXA
i'm trying to write a script and i created a method:
Code:
def Cache.generate_bitmap(filename)
      base_bitmap = Cache.battler(filename, 0)
end
What if i want to delete that bitmap from Cache?
Sorry i'm a noob
 

Heirukichi

Veteran
Veteran
Joined
Sep 24, 2015
Messages
1,403
Reaction score
587
First Language
Italian
Primarily Uses
RMVXA
You can use Cache.clear, but that clears your whole cache.
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
197
Reaction score
68
First Language
English
Primarily Uses
RMXP
Probably something like this
Ruby:
module Cache
  # filepath example: 'Graphics/Battlers/Angel'
  def self.dispose(filepath, hue = 0)
    key = [filepath]
    key << hue if hue != 0
    return unless @cache[key]
    
    @cache[key].dispose
    @cache[key] = nil
  end
end
 

hiddenone

Lurker Extraordinaire
Global Mod
Joined
Feb 19, 2014
Messages
2,433
Reaction score
5,177
First Language
english
Primarily Uses
RMMV

I've moved this thread to Learning Ruby and RGSSx. Please be sure to post your threads in the correct forum next time. Thank you.

 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
207
Reaction score
46
First Language
English
Primarily Uses
RMXP
KK was close to the solution but it can be reduced to its minimum expression.

Code:
module Cache
# filepath example: 'Graphics/Battlers/Angel'
def self.dispose(filepath, hue = 0)
key = [filepath]
key << hue if hue != 0
@cache[key].dispose
@cache.delete(key)
end
end
It's weird how this board doesn't let me include spaces as indentation markers...
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
197
Reaction score
68
First Language
English
Primarily Uses
RMXP
@kyonides If the entry doesn't exist in the cache, you're going to get an "undefined method `dispose` for nil class" error.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
207
Reaction score
46
First Language
English
Primarily Uses
RMXP
Next suggestion...
Code:
module Cache
# filepath example: 'Graphics/Battlers/Angel'
  def self.dispose(filepath, hue = 0)
    key = hue > 0 ? [filepath, hue] : [filepath]
    @cache[key].dispose rescue nil
    @cache.delete(key)
  end
end
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
197
Reaction score
68
First Language
English
Primarily Uses
RMXP
Technically works, but it's bad to use inline rescues. Make it a force of habit to avoid doing that.
I really don't understand why you're trying to "one-up" me by using less lines of code when the solution I posted was enough to close this thread.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,473
Reaction score
6,302
First Language
Indonesian
Primarily Uses
RMVXA
If we go by even lesser lines, we can go by this as well
Code:
module Cache
  def self.dispose(filepath, hue = 0)
    key = hue > 0 ? [filepath, hue] : [filepath]
    @cache.delete(key).dispose rescue
  end
end
But KK's original solution is already work without issue.
 

Killer_Van

Stupid Person
Member
Joined
Jul 19, 2018
Messages
20
Reaction score
2
First Language
italian
Primarily Uses
RMVXA
Thanks a lot to everyone, problem solved!!!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,022
Reaction score
4,762
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

My old project is now a sitcom
How to do implementation the social politcal mechanics in rpg maker? Thank you for quick spark of ideas. Fear of going to the thread lol.
MerlinCross wrote on Switz's profile.
Not sure if you'll see this but I stumbled across your "Open Locker" sprite in a topic. Could I use those?
topic in question
Going to watch an episode of The Office and eat something after this little progress!

Forum statistics

Threads
100,780
Messages
979,430
Members
132,417
Latest member
U2M
Top