| Kovs95 (52) | |||
|
If I declare a local variable and give it a value, can I change that value or make it dynamic? For example, in my dungeon crawler game, I want the player to start at grid[x][y] and I set x = 0 and y = 0 when I declared them. But when the player chooses to move up, down, left, or right, those values of x and y need to change obviously. I posted my code below and bolded the parts im referring to. Thanks so much for everyone's help
| |||
|
|
|||
| ne555 (4385) | |||
|
> But when the player chooses to move up, down, left, or right, > those values of x and y need to change obviously. So change them.
¿what's the purpose of the loop in 62 ? | |||
|
|
|||
| Kovs95 (52) | |
| The loop in line 62 forms the maximum and minimum number of rows, so there are 6 rows. I can make a switch statement and have 4 cases for up, down, left, right. Is that what your saying? | |
|
|
|
| ne555 (4385) | |||
This is the loop I'm referring to
then it will execute the `else' block, ten times. > I can make a switch statement and have 4 cases for up, down, left, right. Is that what your saying? No. If you want for the variables to change, you need to change them. You need to update them according to the movement. | |||
|
|
|||
| Kovs95 (52) | |
|
If the if statement is false, then it will do the else part. I want to do the action once not ten times. How did you get ten times? Is there any way I can call on each case of the switch statement from the "else" part? For example, under "else", I can put "case A" and it does that? Is that possible? | |
|
|
|
| Athar (4466) | |||
You're running this in a loop: for ( col = 0; col < 10; col++)Hence, ten times.
What "else part"? | |||
|
|
|||
| Kovs95 (52) | |
| Can I call on the cases of a switch statement under the 'else' conditions of each 'if statement' in my code. Like the else part in line 121. | |
|
|
|
| Athar (4466) | |
|
switch cases aren't functions, so no, you can't call them. Which is about the right cue, because so far, your program consists only of a single function which is far too long. | |
|
|
|
| Kovs95 (52) | |
| For my for loop that you posted above, I thought that it is basically saying "for these values, this happens". I did not think that those values represent the number of times the condition happens. I was trying to program something that would repeat once every imput of "up, down, left, right". | |
|
|
|