GPWiki.org
GPWiki.org
It is currently Sun May 26, 2013 9:21 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Mar 13, 2008 2:01 am 
Bytewise
User avatar

Joined: Wed Jun 13, 2007 10:38 pm
Posts: 273
Location: Bath, New York, USA
The issue though is I have it setup in a menu choice, so that way I can test each creation process individually, however I go and run the first one, it works fine, but after the first one the other ones appear to run fine BUT they don't appear to give me the information displayed like they should've... Here's the calls below, which I think the issue maybe.

The code is located in my Main function
Code:
   static Item item[] = new Item[100];
   static Monster monster[] = new Monster[100];

...

      while ( menuchoice != 5)
      {
         menuchoice = menu();
         switch(menuchoice)
         {
         case 1: //Create Items
            while (i <=5)
            {
               Item.createItems();
               i++;
            }
            break;
         case 2: //Creates Monsters
            while (i <=5)
            {
               Monster.createMonsters();
               i++;
            }
            break;

...


I removed the extra classes I had with the stuff above because all it had in it was the menu choices. ;)

If the code for each of the things above is needed, tell me please?

Oh and I have debugged this, tried to figure out what is messing with it but I keep getting the same issue.

I have been trying to locate something about this on the wiki or in google and so far no such luck.

_________________
Graduated and working on game now. w00T!

Married 05.02.2009


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 2:18 am 
Dexterous Droid

Joined: Fri Aug 19, 2005 10:34 am
Posts: 3650
I have never used Java so I may be off here, but is "i" being set back to 0 after each use? This can probably be more easily resolved if you use a for/loop instead, too:

Code:
for (i = 0; i < 6; i++)
{
   Item.createItems();
}


So you know exactly what "i" will start and stop at without having to write a few extra lines. I also just find it a bit more clear to use for/loop instead of while/loop or do/while in cases like this where you're starting from A and moving in equal steps to B where A and B are both defined... its the same in the end, but it just allows the reader of the code (yourself) know what kind of loop it is.

_________________
NetGore - Open source online RPG engine


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 11:31 am 
Bytewise
User avatar

Joined: Wed Jun 13, 2007 10:38 pm
Posts: 273
Location: Bath, New York, USA
Went and tried it, nothing changed, I think I may have ta due some more debugging or something. Heh.

_________________
Graduated and working on game now. w00T!

Married 05.02.2009


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 8:56 pm 
Rookie

Joined: Tue Mar 11, 2008 10:14 am
Posts: 3
Well, It would be a little easier to debug with the full code, or the used methods at least. But, here is a shot..

First I wanted to see if the menuchoice = menu(); is returning an int from the user? (I'm assuming so-- but I was wondering if maybe you were establishing a menuchoice before executing that code, in which that call would overwrite it. ('just throwing out suggestions)

Also, I also agree with the above poster, but I would tweak it just slightly to use
Code:
for(int i=0; i<5; i++)
   Item.createItem();

But that is just personal style. 'not sure if it would help at all.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 9:33 pm 
Dexterous Droid

Joined: Fri Aug 19, 2005 10:34 am
Posts: 3650
Yeah, creating the variable in the for/loop when its just being used to iterate is definitely a good idea. I didn't mention it just because he was already leaving it out of his while/loops for whatever reason.

_________________
NetGore - Open source online RPG engine


Top
 Profile  
 
PostPosted: Sun Feb 06, 2011 9:34 pm 
I know this is kinda an old post and you may have already given up on it, but for those who are looking at it now the problem is iterating i in the while loop. If you run case one i will increase and stay at that value, then if you run case 2 it will not even enter the loop because i has already exceeded the range in which it will enter the loop. A fix for this would be like other posted the for loop and instead of declaring i outside the loop declare it inside the for so something like this

for(int i = 0; i <= 5; i++)
{
item.createItems();
}

for(int i = 0; i <= 5; i++)
{
monster.createMonster();
}


Top
  
 
PostPosted: Tue Feb 08, 2011 10:39 am 
Rookie

Joined: Tue Feb 08, 2011 10:35 am
Posts: 1
Could you try a static method as an getNewMonster, getNewMonsterArray(size)


Top
 Profile  
 
PostPosted: Tue Mar 01, 2011 3:22 pm 
Bytewise
User avatar

Joined: Wed Jun 13, 2007 10:38 pm
Posts: 273
Location: Bath, New York, USA
Whoa this got necro'd... LOL, this has been handled though. Thanks all, just never posted the updated results... I was indeed no resetting i at the time. ;) All is good, I fixed the issue. LOL

_________________
Graduated and working on game now. w00T!

Married 05.02.2009


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group