Problem with "while" statement.

Problem with "while" statement.

Postby Leeizazombie » 23 Feb 2014, 16:12

Hey, I'm working on a mini-game, and at a point it checks the whole map and says how much Block.air there is:

Code: Select all

                        byte b1;

                        b1 = Block.air;
                        ushort x2, y2, z2; int currentBlock = 0;
                        List<MCDzienny.Level.Pos> stored = new List<MCDzienny.Level.Pos>(); MCDzienny.Level.Pos pos;

                        foreach (byte b in p.level.blocks)
                        {
                            if (b == b1)
                            {
                                p.level.IntToPos(currentBlock, out x2, out y2, out z2);
                                pos.x = x2;
                                pos.z = z2;
                                stored.Add(pos);
                            }
                            currentBlock++;
                        }


(For some reason MCDzienny doesn't have pos.y at this part)

And when the game starts the underground starts filling with lava, when it does completely the air count is 125, (because of the spawn area) so I run the following code:

Code: Select all
                          while (gameactive)
                        {
                            if (stored.Count == 125)
                            {
                                gameactive = false;

                                Player.GlobalMessage("The current Digger game has ended.");
                                return;
                            }
                        }

But it won't actually run the code (I made a seperate command to make sure the value is 125).
Did I do something completely stupid? :lol:
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Problem with "while" statement.

Postby Conor » 23 Feb 2014, 17:37

Either the gameactive variable is false, or the stored List never reaches a count of 125. Simply include tests for these situations in your code and debug it to find a solution.

For example, put code at the start of the while loop announcing it has started, and put code to announce the count of the list. If you are 100% positive the List count is exactly 125 and you are 100% sure the while loop does begin, then your problem may be that the List count only reaches 125 after the while loop has ended (gameactive variable changes to false).
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: Problem with "while" statement.

Postby Leeizazombie » 23 Feb 2014, 18:21

Well there are only two situations I set the Boolean to false: /digger end and inside that while loop, I never used the /digger end during the process of course. Maybe I could private message the full code if you can see anything I can't?
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: Problem with "while" statement.

Postby Conor » 23 Feb 2014, 20:59

Leeizazombie wrote:Well there are only two situations I set the Boolean to false: /digger end and inside that while loop, I never used the /digger end during the process of course. Maybe I could private message the full code if you can see anything I can't?


Sure
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 1 guest

cron