First of all, my friend made a window in our game that displays the amount of skill points. The problem is, when you gain or lose the points while the window is still there, it doesn't update itself. Not only that it won't close/dispose or whatever it's called.
Below is the script that she made. She's pretty new to Ruby so she hit a brick wall. I have no idea what to do either, so I'm asking for help.
# ===========================================================
# Author: AbsolutePrincess
# ===========================================================
# Displays Skillpoints in the Skill Tree window.
# ===========================================================
class Window_SkillPoints < Window_Base
# =========================================================
# Object Initialization
# =========================================================
def initialize
super(24, 24, 144, 96)
refresh
self.contents = Bitmap.new(width - 32, height - 32)
end
# =========================================================
# Refresh
# =========================================================
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
end
end
Here is a screenshot of the event that brings up the window.
(http://i704.photobucket.com/albums/ww44/mapletookie42/Event.png)
Alright, what she has to do, is alias the Scene_Map methods called 'main' and 'update'.
The alias of main would be this:
class Scene_Map
alias whatever_you_want_it_to_be main
def main
@spwindow = Window_Skillpoints.new
whatever_you_want_it_to_be
@spwindow.dispose
end
end
The update one should call the window's update method.
The window's update method should check if the previous amount of skillpoints is the same as the current one and if that's the case, it should call the refresh method. The refresh method draws the text.
So the text, drawn in the event, is drawn in the refresh method. This way, the event isn't necessary at all :D.
Quote from: SBR* on February 25, 2011, 04:31:11 am
Alright, what she has to do, is alias the Scene_Map methods called 'main' and 'update'.
The alias of main would be this:
class Scene_Map
alias whatever_you_want_it_to_be main
def main
@spwindow = Window_Skillpoints.new
whatever_you_want_it_to_be
@spwindow.dispose
end
end
The update one should call the window's update method.
The window's update method should check if the previous amount of skillpoints is the same as the current one and if that's the case, it should call the refresh method. The refresh method draws the text.
So the text, drawn in the event, is drawn in the refresh method. This way, the event isn't necessary at all :D.
Thank you for the reply. <3
Well, will that even work? It's not a scene. It's a window.
Sorry, I sound like a total moron.
Quote from: Bernkastel on February 25, 2011, 06:25:29 am
Quote from: SBR* on February 25, 2011, 04:31:11 am
Alright, what she has to do, is alias the Scene_Map methods called 'main' and 'update'.
The alias of main would be this:
class Scene_Map
alias whatever_you_want_it_to_be main
def main
@spwindow = Window_Skillpoints.new
whatever_you_want_it_to_be
@spwindow.dispose
end
end
The update one should call the window's update method.
The window's update method should check if the previous amount of skillpoints is the same as the current one and if that's the case, it should call the refresh method. The refresh method draws the text.
So the text, drawn in the event, is drawn in the refresh method. This way, the event isn't necessary at all
.
Thank you for the reply. <3
Well, will that even work? It's not a scene. It's a window.
Sorry, I sound like a total moron.
As you might now, Scene_Map is the scene you're in when you're on a map.
As this window is displayed when on the map, you have to edit Scene_Map to display it automatically: when Scene_Map is called, you load the window and when another scene is called, you dispose the window.
When Scene_Map is updating (when you're on the map), it calls the update method of the window. This update method checks if the content has changed and if it has, it refreshes the content.
In the current script, refresh is completely misused: it is currently used to remove the contents if the method is called. You could better name the method dispose and use 'super', but I think this is already included in Window_Base/Window if it's even necessary.
If your friend doesn't know what alias is: when using 'alias', you sort of overwrite the old method, while the current content of the method is kept, because you change the name of the method. So you change old_method_name to new_method_name and then overwrite old_method_name. Somewhere in the overwriting of old_method_name, you call new_method_name, which holds the content of the original method. So when old_method_name is called, both the new and the original content are executed :D.
def old_method_name
print '1'
end
alias new_method_name old_method_name
def old_method_name
new_method_name
print '2'
end
OUTPUT:
1
2
Well, she's still confused. Could you explain it a little better?
She wants to know how you call the modified/alias Scene_map. That's what she doesn't understand the most.
Also, I forgot to mention that the window is supposed to show the amount of skillpoints depending on which actor is stated.
I guess this was supposed to tell who's skillpoints are being shown:
@spwindow.contents.draw_text(4, 0,
120, 32, "Skillpoints:")
@actor = $game_actors[7]
@spwindow.contents.draw_text(4, 32,
50, 32, @actor.skillpoints.to_s)
Bump.
No more help?
You can pass the actor or the actor's index as an argument to the initialize method.
Something like this:
def initialize(actor_index)
@actor = $game_party.actors[actor_index]
end
I thank you for your help, but I'm still having trouble making the window refresh and close when I want it to..
Have an update for the window be called in the scene's update method. The window's update method should just be checking for changes, key presses, etc, and have it refresh whenever you need it to. For example, if you wanted to have the window "close" whenever the player hit the "B" button, something like this:
def update
if Input.trigger(Input::B)
self.visible = self.active = false
end
end