FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   couldn't delete lib\build\player1.gif
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: couldn't delete lib\build\player1.gif  (Read 566 times)
gkoshra

WWW Email
couldn't delete lib\build\player1.gif
« on: Aug 8th, 2003, 1:18pm »

Hi there, i'm at the very start of making a cruddy fighting game as a kind of template, and had a bit of a problem with a nullPointerException that wasn't immediately obvious as to where it was going wrong, so I started stripping out bits, and got the above message when I close the sketch.
 
Code:

int w = 240;
int h = 160;
 
Fighter player1 = new Fighter();
 
BImage bgimage;
 
void setup()
{
  size(w,h);
  bgimage = loadImage("background.gif");
}
 
void loop()
{
  image(bgimage, 0, 0);
  player1.update();
 
}
 
///////// -----
 
class Fighter
{
 
  int xstart = 50;
  int ystart = 130;
 
  BImage fimage;
 
  Fighter ()
  {
  }
 
  void update()
  {
    fimage = loadImage("player1.gif");
    image(fimage, xstart, ystart-fimage.height);
  }
 
}
 

 
 
Images used are here http://gomako.co.uk/temp/background.gif and here http://gomako.co.uk/temp/player1.gif
 
Is there something odd going on? Or am I missing something? The nullPointerException comes when I do this...
Code:

class Fighter
{
 
  int xstart = 50;
  int ystart = 130;
 
  BImage fimage;
 
  Fighter ()
  {
 fimage = loadImage("player1.gif");
  }
 
  void update()
  {
    image(fimage, xstart, ystart-fimage.height);
  }
 
}

 
btw, the images were done in a few seconds. Honest guv. That's why they're poop.
 
fry


WWW
Re: couldn't delete lib\build\player1.gif
« Reply #1 on: Aug 9th, 2003, 2:01am »

could you post a .zip of your sketch folder?
 
gkoshra

WWW Email
Re: couldn't delete lib\build\player1.gif
« Reply #2 on: Aug 11th, 2003, 10:36am »

Sure, it's here... www.gomako.co.uk/p5/weakAssFightingGame.zip
 
fry


WWW
Re: couldn't delete lib\build\player1.gif
« Reply #3 on: Aug 13th, 2003, 9:05pm »

hm, i'm not getting a NullPointerException when i run it.. where was it showing up?
 
(the "couldn't delete" is a mostly cosmetic thing, and will prolly be fixed for the next release.)
 
gkoshra

WWW Email
Re: couldn't delete lib\build\player1.gif
« Reply #4 on: Aug 14th, 2003, 4:01pm »

Hello,
 
the Null Pointer thing happened when I moved fimage = loadImage("player1.gif"); from the update() part of the class to the constructor. When I run it, the very first line of code got highlighted. If that's any help.
 
I'm running version 58 on Windows 2000.
 
Ben.
 
fry


WWW
Re: couldn't delete lib\build\player1.gif
« Reply #5 on: Aug 14th, 2003, 6:43pm »

oh sorry.. missed that in your msg since downloading your code and coming back to it. (i try to get through these msgs a little too hastily sometimes)
 
the NullPointerException problem is that you're creating the Fighter object outside of setup(). you can't use p5 methods/calls like loadImage() until you're at least inside setup(). stuff outside will be run before setup(), at which time the internal stuff hasn't run its own setup yet.
 
i wonder if this is something to be fixed or just documented. loadImage and others could be made to work, just curious about what's best.
 
(moving to programs.. the couldn't delete thing is a bug but we've got that logged)
 
gkoshra

WWW Email
Re: couldn't delete lib\build\player1.gif
« Reply #6 on: Aug 15th, 2003, 11:52am »

I don't know whether you should fix it if you need to follow this way of working when/if you move on to C++/Java.
 
From what I understand from your post, all p5 methods/calls need to be made in loop() or setup(), or at least when they've run, and if you have classes, they get run first. Is that right? If so, maybe it is a good idea just to add that info as a note in the object data bit in the reference section.
 
Any thoughts?
« Last Edit: Aug 15th, 2003, 3:45pm by gkoshra »  
fry


WWW
Re: couldn't delete lib\build\player1.gif
« Reply #7 on: Aug 15th, 2003, 9:36pm »

right.. using something like a loadImage() outside of a method in java (or c++) wouldn't work either, but as with many things in p5, we're trying to simplify the syntax. so each time someone runs upon one of these issues, we try and evaluate if that's a feature that should be supported, or whether it's something that we need to tell people inside the docs. lots of these (such as the loadImage) are a gray area.
 
benelek

35160983516098 WWW Email
Re: couldn't delete lib\build\player1.gif
« Reply #8 on: Aug 16th, 2003, 5:50am »

for what it's worth, i think it's a better idea educationally if things are kept as they would work in Java - it's a more straightforward learning curve (speaking from experience!)
 
fry


WWW
Re: couldn't delete lib\build\player1.gif
« Reply #9 on: Aug 31st, 2003, 6:55pm »

on Aug 16th, 2003, 5:50am, benelek wrote:
for what it's worth, i think it's a better idea educationally if things are kept as they would work in Java - it's a more straightforward learning curve (speaking from experience!)

so in that case, your vote would mean that his code should have broken this way.
 
i'm not sure, since it meant he was confused (and i didn't notice what was wrong offhand either) and had to go to the bboards for the fix.. it's a tough call. probably better to have a more graceful method of breaking, like complaining with an error that "loadImage() has to be used inside or after setup()"
 
benelek

35160983516098 WWW Email
Re: couldn't delete lib\build\player1.gif
« Reply #10 on: Sep 1st, 2003, 1:58pm »

maybe a more involved description of what setup() is, not only in terms of what it allows the programmer to do, but for the running of p5, would work.
 
obviously a great solution would be for p5 to tell you what you're doing wrong, but if you want to know why it's wrong you still have to come to the board...
 
Pages: 1 

« Previous topic | Next topic »