Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Apidcloud on March 28, 2011, 01:06:47 pm

Title: disposed sprite once again <.< [Resolved] type error FTW
Post by: Apidcloud on March 28, 2011, 01:06:47 pm
Hey there XD

I've created a class that is 'son' of Sprite class.

The class simply does some src's and that so I don't need to do the process to all the pictures <.<
But, when using:
@variable = Bitmap.new(200, 200)
self.bitmap = @variable


Well, when im going to enter the game, it appears' Disposed sprite' <.<

Can someone help me? xD Blizzard helped me once with this but its giving me error on this class now lol
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Blizzard on March 28, 2011, 02:17:08 pm
Where are you doing this? In initialize? In that case you should first call super.
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Apidcloud on March 28, 2011, 03:28:26 pm
Yes, with super it works <.< But I don't understand why I need super lol
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Blizzard on March 28, 2011, 04:04:31 pm
When you call "super", the superclass' method with the same name is called. Before you call the initialize method of Sprite, it is considered non-existent (and disposed). If you try to assign a bitmap to a disposed Sprite instance, you get an error, that's why you first have to call the initialize method of Sprite through "super".
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Apidcloud on March 28, 2011, 04:29:13 pm
so, basically, am i calling initialize method from Sprite class? (by using super in this especiafically case)
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Blizzard on March 28, 2011, 04:34:37 pm
Yes. You should always call super if you derive from a class and override an already existing method (such as initialize).
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Apidcloud on March 28, 2011, 04:39:54 pm
hmm...I see...imagine that a class have 2 arguments.
If I use super in a 'son' class, then it will be with the same 2 arguments right?
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Blizzard on March 28, 2011, 04:49:18 pm
Yes. Though you can change the number of arguments in the method of the derived class, the superclass' method still needs to be called with the proper number of arguments through super. Just keep in mind that for 0 arguments you have to call explicitly "super()". Calling "super" calls the supermethod with the exact same arguments that you got in the current method.

BTW, it's called child class.
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Apidcloud on March 28, 2011, 04:54:28 pm
Well xD, in this case of Sprite, my super is 'super(nil)' xD

So, in the arguments, I just do as i do in a window... xD ok I think I finally get it now xD


thanks a lot, and for 'child class' information xD
Title: Re: disposed sprite once again <.< [Resolved] type error FTW
Post by: Jragyn on April 24, 2011, 11:22:27 am
I know this is fully resolved, but I read it and I am just impressed with Blizzard's knowledge and patience to explain in ways you can understand. If there was a facebook-like button, Blizzard, you'd be pretty popular in my book by now XD