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
186
Reaction score
67
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,425
Reaction score
5,161
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

Veteran
Veteran
Joined
Nov 17, 2019
Messages
155
Reaction score
32
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
186
Reaction score
67
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

Veteran
Veteran
Joined
Nov 17, 2019
Messages
155
Reaction score
32
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
186
Reaction score
67
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,437
Reaction score
6,253
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
6,993
Reaction score
4,739
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 Posts

Latest Profile Posts

Where's this sudden heatwave come from? It's not even sunny, it's just hot. Hate it!
I'm slightly disappointed that the MZ codebase still uses core.js, managers.js, objects.js, scenes.js, sprites.js and windows.js instead of core/Bitmap.js, core/Graphics.js, managers/AudioManager.js, managers/DataManager.js, etc...
just a few more hours until the toughest, most pressure 72 hours of my life, wish me luck guys
Working on some bosses for my game-

Forum statistics

Threads
100,562
Messages
977,241
Members
132,142
Latest member
Meowthsa
Top