CANCELLING "MOVE PICTURE" IF THERE IS NO PICTURE...

Posts

Pages: 1
I started using VX Ace, and I've noticed a lot of my events giving me

Script 'Sprite_Picture' line 54: NoMethodError occured
undefined method 'width' for nil:NilClass

...and figured out that it happens when one of my events is trying to "Move Picture #x" after it has been erased. In most cases, it happens because a separate Parallel Process that Moves Picture of the cursor of a menu while another handles button pressed (Down/Up/Confirm/Cancel). Confirming, for example, erases the cursor's pictures but sometimes too quickly and the cursor's events still tries to move the cursor after it's been erased.
Obviously I can work around this with long waits after switching off the "move cursor's picture" event before erasing the picture...but I have quite a lot of those events by now, and not only cursors...

Isn't there a line I can add in the basic script? Something that tries to says, to paraphrase, "forget about moving the picture if the picture does not exist anymore"?

I didn't have this problem in VX...help please!!
Hmmm... it should be as simple as finding the code for the move and...

Well, I don't know where it is for sure in VX Ace, but in RMXP it's under Sprite_Picture, under update -

At the beginning of the "update" method, it should be a simple matter of adding in the following line before the line with 'super' on it:
return if @picture == nil

If that doesn't work, try this instead:
return if self.bitmap == nil

One of those should, theoretically, handle it - again, I don't have VX Ace to test it, but there shouldn't be that much difference in the way it handles pictures.

But just a question - if you're using VX Ace, why write a menu using events when you can do it, and it runs better, with RGSS?
Hmm, another thing: If you are using a picture based menu, why would you run two events, one for button pressing and one for the cursor to show.

I don't know if this by any point usefull, but in rm2k3 I do this in one event, just updating the cursor movement and placement after I press a button.
author=Travio
Hmmm... it should be as simple as finding the code for the move and...

Well, I don't know where it is for sure in VX Ace, but in RMXP it's under Sprite_Picture, under update -

At the beginning of the "update" method, it should be a simple matter of adding in the following line before the line with 'super' on it:
return if @picture == nil

If that doesn't work, try this instead:
return if self.bitmap == nil

One of those should, theoretically, handle it - again, I don't have VX Ace to test it, but there shouldn't be that much difference in the way it handles pictures.

But just a question - if you're using VX Ace, why write a menu using events when you can do it, and it runs better, with RGSS?


Thanks a lot for your answer.

The first line doesn't seem to do anything for the problem, unfortunately...nothing changed at all.
The second one just stops all pictures from showing up.

If you or anyone has any other ideas, please go ahead!! I'd be SO grateful. I'm pouring a lot of effort into this game, and it uses a lot of pictures...

Regarding why I'm not making menus through RGSS, it's because unfortunately I have no knowledge of scripting (yet). Altough I plan to learn scripting eventually right now I don't have enough time for that and all my spare time and energy is put into working on this game with what I know (I had previous knowledge of RPG maker from a long time ago). I know, I would probably be saved some trouble had I scripting knowledge, but right now its learning is a huge wall.

At any rate, I have so many events that use pictures and that are not menus and cursors, that an anti-crash script for "Move Picture" would be infinitely useful as things are...

author=Trujin
Hmm, another thing: If you are using a picture based menu, why would you run two events, one for button pressing and one for the cursor to show.

I don't know if this by any point usefull, but in rm2k3 I do this in one event, just updating the cursor movement and placement after I press a button.


...you know what...I...don't know why I did this to begin with. Maybe to make the command more fluid (by not forcing the time between selections to be as long as it takes for the cursor to move) but this is not really important after all...lol I think I'll put them in the same event.

That'll help with menus, but not with the rest though, so if any good soul has any advice...?
You don't have to force wait time if you don't do "stop all progress until moved".

Besides that, you could use transparant dummy pictures that you won't see to avoid the picture not found error.
After looking at the rest of the scripts, I figured out why it didn't work - I had made an assumption that the event command for moving a picture used the update function from Sprite_Picture - it does not.

Go into the event Interpreter scripts - in RMXP, there's a set of 7 individual files that help build this class. Find the one with the Move Picture command, in RMXP it's Interpreter 5, and look for the command that is for Move Picture (command_232 in RMXP, but it should be labelled in the comments if you have a legit version of VX Ace.

There should be a line of code that determines the picture number; in RMXP, it reads:
number = @parameters + ($game_temp.in_battle ? 50 : 0)

Immediately under that, add:
return false if $game_screen.pictures.name == ""

This does work in RMXP - I've tested it - and from what I remember of the VX Ace trial, the Interpreter script isn't that much different. Basically, what it does is check to see if that picture number has a file name attached to it; if it doesn't, it exists from the script and says "I couldn't move the picture." An "erased" picture, from what I can tell, is basically just set to be a picture without a file name associated with it (it's slightly more complicated than that, but this is the quickest way I could find to check if the picture was empty).

And yes, this is basically how I learn all programming languages: trial and error. It's probably one of the best ways to learn that I've found. I don't think I've looked at a single tutorial yet (though I have looked at other scripts to see how they do something, and then figured out what each line of code does).
Hmmm...my "Move picture" section in Game_interpreter seems very different from yours in XP...

def command_232
if @params == 0 # Direct designation
x = @params
y = @params
else # Designation with variables
x = $game_variables[@params]
y = $game_variables[@params]
end
screen.pictures[@params].move(@params, x, y, @params,
@params, @params, @params, @params)
wait(@params) if @params
end

after a few minutes of examination, I figured out what all of it means, but since there is no actual line that determines picture number here (instead it seems to have been referenced earlier), I tried it in a few different places that didn't work.

I noticed the wording was different so I tried to make my own line
return false if @params == nil
since it seems @params is the one that refers to the identity of the picture...I might be wrong...at any rate, it didn't work.

Sooo I thought maybe I should just find the place where that picture number (params, if I'm right) was determined so I can put that line there. The only thing I can find above in Game_interpreter is, I suppose,
@params = command.parameters
which I assume just turns previous determined "command.parameters" into the easily referencible @params that are used below...but maybe I'm just not going the right way with this anyway...unless my original line of code is completely wrong, it doesn't seem to help if I put it at the beginning of Move Picture.
Also, are you sure your assumption about Move_Picture using Frame update is wrong?

Any other idea? I'm discovering a buncha things as I go, but I'm still highly lacking in knowledge...thanks again for your time, be assured it's very appreciated :)

author=Trujin
You don't have to force wait time if you don't do "stop all progress until moved".

Besides that, you could use transparant dummy pictures that you won't see to avoid the picture not found error.

You're right, I didn't know about the no-Wait solution, thanks! And I suppose I could just turn them all transparent or 0% size instead of erasing them if nothing else works, that would be more simple altough a bit longer. I think I'll just linger a bit more on the issue to see if there isn't a way to kill the problem at the source, and otherwise I'll just handle each problem one by one (I have a lot of those by now though, because I converted a VX project to a VX ace one)
Haha, I just got the most simple solution for you EVER! I downloaded the trial of RMVX yesterday (nice battle music btw, but the rest of the program is not suited for me) and I thought: why not try to get this bug to help you.

Now, first I didn't get the bug at all, after messing with the picture command I did got it.

Problem, when you place pictures with "center" as origin RMVX will try and find your bitmap (picture) width and devide it by two to get the centerpoint of it. Since there is no picture, it just says: Hey you, there is no picture to get a width from so here is an error in your face.

However, when I first tried to simulate this bug I had my origin selected at topleft. When I do this I don't get the error because it isn't looking for the bitmap width.

So here you go, easy solution for you: Set origin to topleft instead of center!
Pages: 1