RGSS2 WINDOW TROUBLES
Posts
Pages:
1
I've written this code that displays 3 windows when you click on a certain event.
(Window_Enemy is a subclass of Window_Base)
And then self-switch A is turned on, which activates page 2 of the event (the "trigger" of which is a parallel process).
Right now, I simply want it such that if I press the UP key, all three windows created earlier are disposed, and self-switch A is turned OFF.
This doesn't work, however, and I get the "disposed window" error message. Any ideas where I'm going wrong? Thanks in advance!
(I know I could use a conditional branch event command instead of the above 'if' condition, but I figured it'd be useful to know what was going on.)
$enemy_1 = Window_Enemy.new(0,0, 544,
416/3, 1)
$enemy_2 = Window_Enemy.new(0,416/3, 544,
416/3, 2)
$enemy_3 = Window_Enemy.new(0,832/3, 544,
416/3, 3)
And then self-switch A is turned on, which activates page 2 of the event (the "trigger" of which is a parallel process).
Right now, I simply want it such that if I press the UP key, all three windows created earlier are disposed, and self-switch A is turned OFF.
if Input.press?(Input::UP)
$enemy_1.dispose
$enemy_2.dispose
$enemy_3.dispose
key = [1,3,"A"] # where 1 = map ID, 3 = event ID, and A = self-switch
$game_self_switches[key] = false
end
This doesn't work, however, and I get the "disposed window" error message. Any ideas where I'm going wrong? Thanks in advance!
(I know I could use a conditional branch event command instead of the above 'if' condition, but I figured it'd be useful to know what was going on.)
Hmmmm, I haven't seen anybody else use global variables for temporary windows. Usually, they're instance variables; all the code I've seen has @enemy_1 instead, for example:
Any reason why?
Sorry, I'm not very experienced, but I have fixed odd little bugs like this before by messing around :B It might help to add an "if != nil" conditional.
@enemy_1.dispose if @enemy_1 != nil
if YEM::BATTLE_ENGINE::DEFAULT_VICTORY_MESSAGE @message_window.dispose @message_window = Window_BattleMessage.new @info_viewport.oy = Graphics.height * 8 else
Any reason why?
Sorry, I'm not very experienced, but I have fixed odd little bugs like this before by messing around :B It might help to add an "if != nil" conditional.
@enemy_1.dispose if @enemy_1 != nil
Nah, not really. Good spot! *fixes*
Unfortunately the if != nil conditional didn't help..cheers anyway!
EDIT: Okay, using Input.trigger instead of Input.press seems to have helped. No idea why. And I had to change the instance variables back to global variables: probably so I could access the methods in Window_Base?
HOWEVER, problem's still not completely solved. If I press UP again, I get the disposed window message again probably meaning my method for turning the self switch off isn't working. hmm...
Unfortunately the if != nil conditional didn't help..cheers anyway!
EDIT: Okay, using Input.trigger instead of Input.press seems to have helped. No idea why. And I had to change the instance variables back to global variables: probably so I could access the methods in Window_Base?
HOWEVER, problem's still not completely solved. If I press UP again, I get the disposed window message again probably meaning my method for turning the self switch off isn't working. hmm...
You can't update/affect a disposed window/sprite/bitmap. Once it's disposed it shouldn't be used anymore, including disposing of it. Include a check to make sure you aren't doing it:
if Input.press?(Input::UP) $enemy_1.dispose unless $enemy_1.disposed? $enemy_2.dispose unless $enemy_2.disposed? $enemy_3.dispose unless $enemy_3.disposed? key = [1,3,"A"] # where 1 = map ID, 3 = event ID, and A = self-switch $game_self_switches[key] = false end
Cheers, it works for the most part but when I step back onto the event and press the action key again the event fails to execute.. However after bringing up the menu and closing it the event works fine...?
Pop in some messages to make sure both pages are executing properly. I think something is fucking up the event from going back to the first page. If you can go FirstPage->SecondPage->FirstPage then I'm not sure what the problem is.
Okay, after some testing I've determined pressing Up while self switch A is turned on does NOT turn self switch A off. I'm sure I've got my parameters right. :S I'll keep working on it. I shall not back down
author=GreatRedSpirit
You can't update/affect a disposed window/sprite/bitmap. Once it's disposed it shouldn't be used anymore, including disposing of it. Include a check to make sure you aren't doing it:
Oh! I thought it might be something like this, which is why I suggested the nil check.
I looked at how the game interpreter handles this, and:
def command_123
if @original_event_id > 0
key = [@map_id, @original_event_id, @params]
$game_self_switches = (@params == 0)
end
$game_map.need_refresh = true
return true
end
#----
Maybe that has something to do with it? Freakin' shot in the dark, but...
$game_map.refresh
throw it in, so the game knows to update the map with the changed switch!
From elsewhere:
def setup_starting_event
if $game_map.need_refresh # If necessary, refresh the map
$game_map.refresh
end
Aaaah Versalia you're a genius I fucking love you to pieces
Those windows will auto-dispose by the garbage collector if they are not being updated, btw.
I would suggest adding something to Scene_Map's update method to something along the lines of
I would suggest adding something to Scene_Map's update method to something along the lines of
$enemy1.update if $enemy1
$enemy2.update if $enemy2
$enemy3.update if $enemy3
Pages:
1

















