Page 1 of 1

Problem with "while" statement.

PostPosted: 23 Feb 2014, 16:12
by Leeizazombie
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:

Re: Problem with "while" statement.

PostPosted: 23 Feb 2014, 17:37
by Conor
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).

Re: Problem with "while" statement.

PostPosted: 23 Feb 2014, 18:21
by Leeizazombie
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?

Re: Problem with "while" statement.

PostPosted: 23 Feb 2014, 20:59
by Conor
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