Click here to Skip to main content
12,556,922 members (52,397 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C# XNA3.0
Dear CodeProject,

I have been working on my game for the past couple of days, and for some odd reason the following code won't work:

// -- Write the world bytes.
for (int i = ChunkSize; i > 0; i--)
    for (int j = ChunkSize; j > 0; j--)
        // -- Block.
        char Block;
        if (ChunkY > 0 || (ChunkY == 0 && j > World.ChunkSize / 2))
            Block = (char)BlockID.BLOCK_GRASS;
            Block = (char)BlockID.BLOCK_AIR;
        // -- Add Return.
        _ReturnString = _ReturnString + Block.ToString();

Well, in fact, it works. But the only thing that doesn't work is this part:

(ChunkY == 0 && j > World.ChunkSize / 2))

Also keep in mind that I am writing the world from the end to the beginning, the reason why is because I read it out afterwards and it's backwards if I don't also write it backwards.

If you do not understand my problem: Basically, I am creating a flatgrass, but if the chunkY coordinate is 0 it should fill the grass all the way to the middle instead of the whole chunk. And it's basically only doing it for the whole chunk thing.
Posted 23-Dec-12 1:48am
Yvar Birx2.4K
Updated 23-Dec-12 1:59am
Shahin Khorshidnia 23-Dec-12 8:44am
So what is your C# problem? You may correct the algorithm firstly.
Yvar Birx 23-Dec-12 9:21am
My problem is as I said this: "(ChunkY == 0 && j > World.ChunkSize / 2))". There is no algorithm as this is flat grass.
Daniele Rota Nodari 27-Dec-12 7:15am
You are looping j from ChunkSize to 1 and comparing it with World.ChunkSize / 2.
Are ChunkSize and World.ChunkSize in some way related?
What are current values for ChunkSize, ChunkY, World.ChunkSize?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161026.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100