| brandonator (123) | |||
|
//yes i know system commands are evil, and i only used it for the sake of showing //my code on the forums in 1 file, got my own clearscreen function. I need help getting the map for my game to only print me 6 characters above, below, left, and right of my player (as if my player ( @) had a line of sight, and when i move, the map will update)
| |||
|
Last edited on
|
|||
| maeriden (341) | |
| In the ShowMap() function pass the map as argument and search it for your player character. When it finds it make it print only the elements around the player, which are [x-1[y-1], [x][y-1], [x+1][y-1], [x-1][y], [x][y] (the player itself), [x+1][y] | |
|
|
|
| brandonator (123) | |
| Problem is, it thinks x and y are undefined in that function (x,y only defined in main). And if i make the x and y variables globals, then the map messes up because both the map, and the variables are global. | |
|
Last edited on
|
|
| maeriden (341) | |
|
Well, that was pretty stupid of me, I didn't notice you already keep track of the player position. In this case there's no need to search the map for the player. Pass 'x' and 'y' to ShowMap() and make it print only the characters you need. Consider making 'map' local to main and passing it to ShowMap(), as it's bad to get used to having globals. By the way, even if they were global, they wouldn't get messed up, because they are not modified when printing the map. Of course this line of thinking is bad and must be avoided | |
|
|
|
| brandonator (123) | |
| im having trouble passing it from main, when i use it in showmap, it says x and y are undeclared in first use of this function, so can you play around w/ this code? | |
|
|
|
| maeriden (341) | |
| Post the prototype and how you call it | |
|
|
|
| brandonator (123) | |||
The nonworking prototype, because x and y are undeclared, it says
| |||
|
Last edited on
|
|||
| MikeyBoy (235) | |
| So as maeriden said, you need to pass x and y into the ShowMap function. | |
|
Last edited on
|
|
| maeriden (341) | |||
Now there's another issue. What if x=4 ? That would print starting from map[-2][0]. The same thing happens if 'i' or 'j' are smaller than 0 or greater than the array size. You have to implement a way to check if you go out of bounds | |||
|
Last edited on
|
|||
| brandonator (123) | ||||
i tried setting parameters to make sure it didn't print, if it went over or under, but even when i do that it messes up; if i go too far down it prints strange characters; if i go too far left or right it shows the opposite side of the map, please help, thanks current code //please test any changes before presenting a fix
| ||||
|
Last edited on
|
||||
| brandonator (123) | |
| Any help would be great. | |
|
|
|
| MikeyBoy (235) | |
| Why not use a debugger - or even just print out some useful debugging output - to see what's going on? | |
|
|
|
| brandonator (123) | |||||
the program works, its just that it prints out random emoticon characters if i go too far down or up when the formula
(i need help doing the parameters that make it not do the weird displaying as i keep messing up and it does not work) | |||||
|
Last edited on
|
|||||
| Imadatobanisa (647) | |
|
You asked : Print characters (arrows) up - down - left - right around the character position? Have you solved your delay problem yet? | |
|
Last edited on
|
|
| brandonator (123) | |
| no because when i go out of boundrys it does weird thisgs, see above post | |
|
|
|
| Imadatobanisa (647) | |
| This is "Printing array map problem", right? | |
|
|
|
| brandonator (123) | ||
yes, it is a printing map problem, and even if i tried to set parameters it still prints funny thats what i need help fixing | ||
|
Last edited on
|
||
| Imadatobanisa (647) | |||||||||||||
I think, your code prints a specific range of map around the character. Now you want to add an additional feature. Consider : First, I define a few parameters :
1-
E.g : y = 3
Certainly you don't want your program to access an invalid array item? You want (i >= 0), not (i < 0)? And, the solution : Put a comparison expression. 2-
E.g : y = 29
Similar case... And, the solution : Put a comparison expression. And x... Similar solutions... So we'll have the right code :
You'll need to define some const variables (such as : Rows, Columns) Hope this helps. Do you know the hand-checking skill? | |||||||||||||
|
Last edited on
|
|||||||||||||
| brandonator (123) | |
| Thanks for the help, it worked perfectly :) | |
|
|
|