Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Noob on January 17, 2011, 05:52:33 pm

Title: displaying an icon
Post by: Noob on January 17, 2011, 05:52:33 pm
hey i'd like to now how to display a small 24 x 24 icon in the upper right corner of the game screen. i'd like someone to please tell me the code commands for calling and dismissing it.  thanks :)
Title: Re: displaying an icon
Post by: nathmatt on January 17, 2011, 06:40:05 pm
does it need to update if not just do this to make it
$Icon = Sprite.new
$icon.x,$icon.y = x,y # the x and y you want it to be
Icon.bitmap = RPG::Cache.icon(filename) # the icon name

and just use
$icon.dispose # to remove  it
Title: Re: displaying an icon
Post by: Noob on January 18, 2011, 07:34:27 pm
It fails :( it gives me a long error list a little similar to the one it gives if you put the main script above other scripts. Odd. I used an event to call this script:
$Icon = Sprite.new
$icon.x,$icon.y = 100,100 # the x and y you want it to be
Icon.bitmap = RPG::Cache.icon(testicon) # the icon name
Anything I did wrong? (I tried getting rid of the comments and that didn't help)
Title: Re: displaying an icon
Post by: ForeverZer0 on January 18, 2011, 07:48:29 pm

$icon = Sprite.new
$icon.x, $icon.y = 600, 16
$icon.bitmap = RPG::Cache.icon(ICON_NAME)


Use that in a script call. Replace ICON_NAME with the filename of the icon. It needs to be written as a string, with quotation marks around it. For example, if your icon's filename was test. You would set the icon's bitmap like this:


$icon.bitmap = RPG::Cache.icon('test')


You need to use the the script call to dispose it when you no longer need it. Here is a safer method that won't crash the game if the icon has already been disposed.


if $icon != nil && !$icon.disposed?
 $icon.dispose
end



The icon obviously has to be in your Graphics/Icons directory as well.
Hope that was helpful.
Title: Re: displaying an icon
Post by: Noob on January 19, 2011, 04:55:17 pm
I get an error that says wrong number of arguements 0 for 1.
Title: Re: displaying an icon
Post by: nathmatt on January 19, 2011, 05:14:49 pm
can you copy the code you put and post it
Title: Re: displaying an icon
Post by: Noob on January 19, 2011, 05:19:40 pm
Sure, here's what I tried after importing my 24 X 24 icon, testicon.
$icon = Sprite.new
$icon.x, $icon.y = 600, 16
$icon.bitmap = RPG::Cache.icon
('testicon')
Title: Re: displaying an icon
Post by: nathmatt on January 19, 2011, 05:25:49 pm
here this should make it easier in an event script command use show_image(image) image should be the image name so use show_image('testicon') for you example then use remove_image to get rid of it
class Interpreter
 
  def show_image(image)
    @icon = Sprite.new
    @icon.x, $icon.y = 600, 16
    @icon.bitmap = RPG::Cache.icon(image)
  end
 
  def remove_image
    @icon.dispose if @icon != nil && !@icon.disposed?
  end
 
end
Title: Re: displaying an icon
Post by: ForeverZer0 on January 19, 2011, 08:48:03 pm
Quote from: Noob on January 19, 2011, 05:19:40 pm
Sure, here's what I tried after importing my 24 X 24 icon, testicon.
$icon = Sprite.new
$icon.x, $icon.y = 600, 16
$icon.bitmap = RPG::Cache.icon
('testicon')



You changed the code.
The () have to be right after the call.
If it doesn't fit on the same line, set the filename to a variable in the line before it.

name = 'FILENAME'
$icon.bitmap = RPG::Cache.icon(name)