Jump to content
  • Advertisement
Sign in to follow this  
ChristianFrantz

Simple for loop issue

This topic is 2154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I took your advice and am now using a list. It makes more sense in the long run :p. I generate the list with a while loop that exits once the variable gets to 100.

How am i setting the world matrix for the list? Cubes[x * z] gives me An error "cannot modify the return value of <stuff.Cube>.this[int] because it is not a variable. My code looks exactly the same as the one above, only the C is capitalized because I'm using the list now

Share this post


Link to post
Share on other sites
Advertisement
Your Cube is a struct (a value type), you can't modify its properties if you use [] of List<T>. That's why I said to use Add()
 
    Cube cube = new Cube();
    cube.World = Matrix.CreateTranslation(new Vector3(x, 0, z));
    cube.AtlasCoordinate = new Vector2(rand.Next(0, 2), rand.Next(0, 2));
    cubes.Add(cube);

or shorter:
 
    cubes.Add(new Cube()
        {
            World = Matrix.CreateTranslation(new Vector3(x, 0, z)),
            AtlasCoordinate = new Vector2(rand.Next(0, 2), rand.Next(0, 2))
        });

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!