i have a game i'm making. i need to save all the text that is on the screen to a file. how can i do this? it needs to be like how when you write a text document in the terminal u save all that text to a document. just simple like that. i can upload some code of my game too if needed
Now, if I understand your two questions...
What if you used a two dimensional array that had the contents of what was at each "block" of the screen? Each type of object could have a different code (say unsigned ints to keep it simple and fast).
0 = nothing
1 = player
2 = block_type_1
3 = block_type_2
You could save using this format and I'm thinking it would be fairly simple to represent the contents onto the screen. Modifying a file that just had one array would take no time at all...
agent047 its not anything great. its a terminal based game so i dont think it will be in your interest. im still learning. heres a video to one of the older versions of it tho https://www.youtube.com/watch?v=UoBozexLMxs still though can anyone help me with getwin() and putwin()? i think it will be the best way for my program to work but i cant figure out all the arguments for it and stuff
ok heres a link to the actual code. i think i have it set up like it shows how to use putwin() and getwin() on this link: http://pubs.opengroup.org/onlinepubs/7908799/xcurses/putwin.html
now heres my code: http://pastebin.com/2rCVgSkd
i put a note where i have the saving setup at. the file 'world' is in the same folder as the 'ncursesv6.cpp' file (home folder). it just isnt doing anything when i press 'k' to save or 'l' to load. can anyone fix it??? please ive literally been trying to get this saving to work for weeks
ok i have almost figured it out. i tried scr_dump() and scr_restore() and almost have it figured out. that problem is after you save it, and then load it back up, the screen shows the new characters from the saved file but doesnt update the properties. what i mean by that is, i have it made to where you cant walk through a '#'. after you load the saved file back up any '#' that just loaded up you can walk thru. i dont want you to be able to walk thru it after you load it back up. here is a little slip of my code...
1 2 3 4 5 6 7
doupdate(); //this is where it gets funky and needs to be fixed
ok people i finally figured it out. after weeks of constant work on it i got it. so you first have to declare a file somewhere inside the loop. i did FILE * world; exactly like that, just below where i declared all of the varriables. then to save the file using putwin i used this code under an if statement:
1 2 3
world = fopen("world.win", "w");
then under another if statement, with getwin i did:
1 2 3 4 5
world = fopen("world.win", "r");
stdscr = getwin(world);
things to note:
w in the putwin means the file is opening as a writable file. it also will create a new file in the process if the file world.win isnt already there. the r in getwin means its a readable file.
hope this helps someone! its a big relief for me lol