Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have problem in very simple console app, code looks like this.

int x - player moving and changing axis "x" and I want make full history of moving via array. See code(only example) below...

Thank you for your help and answer

  int round = 0;

  while(infinity){

  int[] PosXSave = new int[round + 1]; //theoretically infinity size of arrray.

  PosXSave[round] = x; //every round i want save current value of x, but 
                       //only last save have propertly value and rest are
                       //zero or other number

  round++

  }
share|improve this question

closed as off-topic by Anko, Byte56 Apr 13 at 14:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Byte56
If this question can be reworded to fit the rules in the help center, please edit the question.

    
I don't understand the question or your code. Did you mean to declare PosXSave before the while? –  Anko Apr 13 at 13:17
    
My god, now I tryed declare array out of while and save position working propertly. Sorry for stupid question :-( –  Masherák Apr 13 at 13:23

1 Answer 1

Using array might be bit faster, but List would be easier to use in this case.

List<int> history = new List<int>();
while(infinity){

 history.Add(x);

}
// round is history.count;
share|improve this answer
    
Thank you for your answer, problem was in declare array in while. :-) –  Masherák Apr 13 at 13:55
1  
Yeah, i know. I still wanted to point you to List. List is like array, but it automatically resizes, so you can just keep adding items –  Katu Apr 13 at 13:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.