ok so i have this projekt where i have this attribute currentField in my class and i define that in my code
public void RollDiceAndMove()
{
Dice.Roll();
if (oldField == 0)
oldField = 1;
currentField = oldField;
lastThrow = Dice.GetDices();
currentField = GameBoard.Move(currentField, lastThrow);
oldField = currentField;
}
when i then try in another place to go and get currentField
public string LandedOn()
{
board = GameBoard.GetBoard();
string temp = board[currentField-1];
return temp;
}
then currentField = 1 again even though i gave it a value before. it is probally easier to see what i mean if u get the full projekt
please take a look and help me because i cant seem to find the error that keeps resetting the value of it
Loading
Suthish NairPosted Oct 28, 2010, 3:22 PM
becoz your setting your field value from other class. it getting initiated to zero again.
Rene NielsenPosted Oct 28, 2010, 3:56 PM
Rene NielsenPosted Oct 28, 2010, 1:01 PM
while (j < 40)
{
switch (Turn)
{
case (1):
PlayerRollDiceAndMove(1);
tempPrint = "Spiller " + Turn + " kastede " + players[Turn-1].LastThrow() + "\nog kan nu rykke frem til " + players[Turn].LandedOn();
Turn++;
j++;
break;
case (2):
PlayerRollDiceAndMove(2);
tempPrint = "Spiller " + Turn + " kastede " + players[Turn-1].LastThrow() + "\nog kan nu rykke frem til " + players[Turn].LandedOn();
Turn++;
j++;
break;
}
if (Turn > 2)
Turn = 1;
}
it still gives me error in this code when i press the start game button
public string LandedOn()
{
board = GameBoard.GetBoard();
string temp = board[currentField-1];
return temp;
}
"Index was outside the bounds of the array."
and if i step through it to see where the error is i seem to come to the conclusion that each time both players have made their first throw and moved to a position currentField, then when they come back to the RollDiceAndMove()
public void RollDiceAndMove()
{
Dice.Roll();
if (oldField == 0)
oldField = 1;
currentField = oldField;
lastThrow = Dice.GetDices();
currentField = GameBoard.Move(currentField, lastThrow);
oldField = currentField;
}
the currentField seems to be reset to 1 again
and not having the value i assigned before which was where they moved to in the first round (eg. start position 1 + 9 throw = currentField 10)
:)
Felipe RamosPosted Oct 28, 2010, 10:38 AM