Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 92 93 [94] 95 96 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 908850 times)

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1395 on: February 09, 2012, 10:14:21 pm »

The code you posted works fine in my test environment.  Check to see if FunkyCritter isn't extending Critter correctly.  If it can't find FunkyCritter, then make sure it's either defined in the same package as your code or you import the package that it is in.  If it isn't either of those, then post the exact error message you're getting.

1. Check the spelling of the function. Make sure you got upper and lower case where it needs to be.
2. Check the visibility of the function. If it is internal, you are going to need to find another way to sneak your guy in there, because the front door is tight!
3. Check you have the right number and type of arguments. It might need more than just the critter.
4. Double check that FunkeyCritter does indeed inherit from Actor.

Everything is correct with it. It is called identically to the previous call, except with a class that extends Critter. Critter extends Actor, so it should all work. It just doesn't for some reason. The error message I was getting is what I posted earlier:

Code: [Select]
method world.add(FunkyCritter) cannot be found

Also, I have a question, how come when I use using namespace string, it doesn't work, yet I have to use functions in the namespace with the scope resolution "::"
such as string::size_type,
I don't know how well I worded that, basically string::size_type works, but using namespace string; size_type doesn't, but to my understanding of namespaces it should,

That would be because string is a class, not a namespace. std is a namespace, and you can use using namespace std; to bring the std namespace into the global namespace. string::size_type is a static member of the string class, so you have to use :: to bring it into scope.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1396 on: February 09, 2012, 10:18:22 pm »

thank you,  I haven't gotten to classes yet, or else I would have been able to figure that out prolly.

i'm about to start chapter 9 of my book,  which is about arrays, on page 470
chapter 10 is about structs,
and chapter 11 is about classes, starting on page 590

O_O 120 pages of structs and arrays, woohoo
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1397 on: February 09, 2012, 10:33:50 pm »

I think that error is saying that it can't find a method in ActorWorld called add that takes in a type FunkyCritter as a parameter.  The most reasonable cause would be that something is going wrong with inheritance.  It should be smart enough to implicitly cast your FunkyCritter to an Actor, but it wouldn't hurt to do the cast explicitly as a sanity check.  Otherwise it's saying it can't find the FunkyCritter class.  It's safe to assume that FunkyCritter extends Critter, is in the same package as the class containing the main method, you have your classpaths set correctly, and everything has been saved, right?
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1398 on: February 10, 2012, 12:25:50 am »

Ok this is really annoying, because I got this to work in the past, and it wasn't even that hard, and I ended up changing it and now I can't recall how to do it again, silly me I know.
SDL, working with surfaces. I have a single image that has all tiles on it, and so I need to split that up into each tile, and throw it into an array. Current code looks a little like this.

Code: [Select]
        private Surface[] getSpriteArray()
        {
            Surface spriteMap = new Surface("terminal.png");
            List<Surface> sprites = new List<Surface>();

            for (int x = 0; x < spriteMap.Width / tileSizeX; x++)
            {
                for (int y = 0; y < spriteMap.Height / tileSizeY; y++)
                {
                    //So the source rectangle would be:
                        //X = x * tileSizeX
                        //Y = y * tileSizeY
                        //Width = tileSizeX
                        //Height = tileSizeY
                    //sprites.Add(new Surface(spriteMap, HOW DO I TELL IT THE SOURCE RECTANGLE?!?));
                }
            }
            return sprites.ToArray();
        }

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1399 on: February 10, 2012, 12:54:58 am »

It's distinctly possible I'm misunderstanding the SDL documentation, given that I've never used SDL before...but it looks like you call SDL_SetClipRect and pass it an SDL_Surface and an SDL_Rect.  It looks like when you call SDL_BlitSurface, you'll be giving it the source and destination surface and source and destinations rectangles.  Something like that, anyway...I'm pretty sure you're looking to use SDL_Rect in some manner, at least.

http://www.libsdl.org/cgi/docwiki.cgi/SDL_Surface
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1400 on: February 10, 2012, 02:56:29 am »

Everything is correct with it. It is called identically to the previous call, except with a class that extends Critter. Critter extends Actor, so it should all work. It just doesn't for some reason.

Perhaps add this?
import info.gridworld.actor.FunkyCritter;
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1401 on: February 10, 2012, 08:19:10 am »

I think that error is saying that it can't find a method in ActorWorld called add that takes in a type FunkyCritter as a parameter.  The most reasonable cause would be that something is going wrong with inheritance.  It should be smart enough to implicitly cast your FunkyCritter to an Actor, but it wouldn't hurt to do the cast explicitly as a sanity check.  Otherwise it's saying it can't find the FunkyCritter class.  It's safe to assume that FunkyCritter extends Critter, is in the same package as the class containing the main method, you have your classpaths set correctly, and everything has been saved, right?

Perhaps add this?
import info.gridworld.actor.FunkyCritter;

The two classes are indeed in the same package. I can do this:

Code: [Select]
FunkyCritter c = new FunkyCritter();
world.add(c);

But, I get the same error on world.add(c);. I even attempted casting it to an Actor, but then I got an error about the cast. I don't remember the exact error message, and the code is on a different computer, so I can't tell you exactly what it said, but it was something along the lines of invalid cast.

As a sanity check, I made sure that FunkyCritter does indeed extend Critter.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1402 on: February 10, 2012, 11:42:03 am »

Everything is correct with it. It is called identically to the previous call, except with a class that extends Critter. Critter extends Actor, so it should all work. It just doesn't for some reason.

Perhaps add this?
import info.gridworld.actor.FunkyCritter;

That should throw a compilation exception.  Assuming I'm right in thinking he's using this api, then there's no such thing as FunkyCritter in the info.gridworld.actor package.  He would have had to define it himself in a local package.

All the same, change the import to
Code: [Select]
import info.gridworld.actor.*
That imports everything in that package.  There are exactly six things in that particular package.  Just import it all to keep things clean.  You'll probably need all of them anyway.  Besides, it's a sanity check in itself.

I think that error is saying that it can't find a method in ActorWorld called add that takes in a type FunkyCritter as a parameter.  The most reasonable cause would be that something is going wrong with inheritance.  It should be smart enough to implicitly cast your FunkyCritter to an Actor, but it wouldn't hurt to do the cast explicitly as a sanity check.  Otherwise it's saying it can't find the FunkyCritter class.  It's safe to assume that FunkyCritter extends Critter, is in the same package as the class containing the main method, you have your classpaths set correctly, and everything has been saved, right?

Perhaps add this?
import info.gridworld.actor.FunkyCritter;

The two classes are indeed in the same package. I can do this:

Code: [Select]
FunkyCritter c = new FunkyCritter();
world.add(c);

But, I get the same error on world.add(c);. I even attempted casting it to an Actor, but then I got an error about the cast. I don't remember the exact error message, and the code is on a different computer, so I can't tell you exactly what it said, but it was something along the lines of invalid cast.

As a sanity check, I made sure that FunkyCritter does indeed extend Critter.

That first statement is contradictory.  You wouldn't be importing anything from this jar file or packages if you were working from within the same package.  You either imported the existing code and started modifying things from there or you imported the jar file and started modifying from your own package.  I've been assuming you're importing the jar file and that you have the StuffRunner and FunkyCritter classes in the same package separate from the gridworld packages.

The second statement is what interests me.  If you got a ClassCastException while trying to cast it from a FunkyCritter to an Actor, something is wrong.  Thirty-second sanity check; create an ordinary Critter and cast it to an Actor.  If that fails, something is horribly wrong.  Otherwise, there's something wrong with the FunkyCritter class definition.

I've never used gridworld before, but it's apparently freely available.  Assuming the gridworld.jar is in your class path, this should work.  It's working fine in my test environment, anyway.  Here's my test environment.  It looks more or less like yours does, right?
Spoiler (click to show/hide)

Beyond that, I'd need to actually see your FunkyCritter class.  I'm running out of obvious errors.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1403 on: February 10, 2012, 04:06:21 pm »

Try importing the header file. It could be compiling the place where it is needed before it is compiling the class itself, thus it doesn't know that it is a subclass of actor yet.
EDIT: Oh wow, that thing that was giving me trouble yesterday. I just solved it within seconds. Strange. Well what ever.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1404 on: February 10, 2012, 05:29:28 pm »

Try importing the header file. It could be compiling the place where it is needed before it is compiling the class itself, thus it doesn't know that it is a subclass of actor yet.
EDIT: Oh wow, that thing that was giving me trouble yesterday. I just solved it within seconds. Strange. Well what ever.

This is Java.  There are no header files.  Just import the package that the code is from and setup your class paths and you're set.

Congrats figuring out your problem.  I never cease to be amazed at that ability to stare at something for hours, leave it for awhile, and then instantly understand it the next time I see it.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1405 on: February 10, 2012, 05:31:27 pm »

Wait, we are working in Java now and it is having these problems?
A plot most foul... Java shouldn't be subject to such issues.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1406 on: February 10, 2012, 05:53:42 pm »

Yeah, it's a little crazy.  I'm still not convinced everything is configured correctly  Assuming it is, then sometimes the IDE or Java screw up...that's a fairly simple progression...if one fails, move to the next.

1. Create a new source file and copy the code there.
2. Create a new package and copy the data there.
3. Create a new project and copy the data there if using an IDE.
4. Create a new workspace/directory and copy the data there.
5. Reinstall the IDE if you're using one.
6. Reinstall Java.
7. Ask for help.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1407 on: February 10, 2012, 07:57:33 pm »

That first statement is contradictory.  You wouldn't be importing anything from this jar file or packages if you were working from within the same package.  You either imported the existing code and started modifying things from there or you imported the jar file and started modifying from your own package.  I've been assuming you're importing the jar file and that you have the StuffRunner and FunkyCritter classes in the same package separate from the gridworld packages.

I meant that the client class and the FunkyCritter class are in the same package. I have indeed imported the jar.

The class does not work on the computer I was using, any of my classmates' computers, or my instructor's computer. We all got the same error. I didn't think to pull the code off of the school computer onto a flash drive, but I'll do that Monday so I can test on my home computer.

I installed Java and Gridworld on my personal computer, and that test program works fine. The thing is, my class is essentially identical to that, only with the act method filled out and a few other superclass methods overridden (processActors being one that I remember overriding). I'm beginning to wonder if it's an issue with the version of Gridworld that we have, because it may not be the newest version.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1408 on: February 10, 2012, 09:05:09 pm »

My test works fine on my machine.  Your test apparently works fine on your machine.  That implies something is wrong with the school's system.  It's either the library in the jar file, the IDE, or the JVM.  We might be able to test the first...the GridWorld News page seems to contain download links for many older versions of GridWorld from 0.10 to 1.02.  It's probably every release.  Grab the version your school is using and try it.  If that works, then maybe the school's copy is corrupted.  I'm going to assume it's not since that tends to make files completely unusable.  That would mean the problem is in the IDE or JVM.  You can try the first half of my earlier recommendations for dealing with a bad IDE or JVM.  You won't be able to reinstall anything, but you can try replacing stuff.  If none of that works and your code works at home, then it might be an issue with your user account on the school network.  Oh, and if you're copying code around, paste it into Notepad before it's final destination.  You may very well be getting screwed over by invisible special characters or something stupid like that.  Notepad is solely plain text and should whip them out; or at least make them apparent...I forget the actual behavior for Windows Notepad...

EDIT:
I don't suppose you can remotely connect to your school's network and grab the project?
« Last Edit: February 10, 2012, 09:11:08 pm by Stargrasper »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1409 on: February 10, 2012, 09:50:42 pm »

I just realized I do indeed have a copy of Gridworld on my flash drive from a school computer. It's version 0.96. I'll push my instructor to have us use a newer version, in hopes that updating it will solve this issue.

EDIT: It seems 0.96 is the official CollegeBoard-sanctioned version. Armokdamnit.
« Last Edit: February 10, 2012, 09:55:35 pm by Mego »
Logged
Pages: 1 ... 92 93 [94] 95 96 ... 796