Computer Science Canada

How do you Save a game and rerun it ??

Author:  livingheaven [ Mon Mar 29, 2010 7:22 pm ]
Post subject:  How do you Save a game and rerun it ??

What is it you are trying to achieve?
<to able to load a saved game >


What is the problem you are having?
<Doesnt know and understand how to load a saved game >



Please specify what version of Turing you are using
<Newest>

Can some one explan how to load a saved game in turing ? Question Question Question

Any help would be great. Very Happy

Author:  USEC_OFFICER [ Mon Mar 29, 2010 7:30 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

Look at file input/output. That's what I used.

Author:  livingheaven [ Mon Mar 29, 2010 7:38 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

Looking at it right now, but they use seek and tell, but i dont know what to do after you get the saved information...

is it something like

var stream : int
var file : string
open :stream, "text.txt" seek
seek :stream, file

then im stuck ..... =.= Question Question Question

Author:  USEC_OFFICER [ Mon Mar 29, 2010 7:54 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

Bam

Turing:
var file, chips : int
var s : string
open : file, "Save1.txt", get

get : file, s :*
get : file, chips

put s
put chips

close : file


That's what I used.

Author:  chrisbrown [ Mon Mar 29, 2010 7:58 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

Use seek and tell only when you need to read from a specific location in the file. Look up read and write instead, they are a little more intuitive.

Saving:
Turing:

var textToSave : string := "This can be almost anything; a number, a string, or a record, at the very least."
var stream : int
var file : string := "text.txt"
open : stream, file, write
write : stream, textToSave
close : stream


Loading:
Turing:

var textToGet : string
var stream : int
var file : string := "text.txt"
open : stream, file, read
read: stream, textToGet
close : stream


I should point out this is (basically) for saving variables. If you want to save text that is human-readable, use put and get.

Author:  livingheaven [ Mon Mar 29, 2010 8:07 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

oh . ok i'll give it a try

Author:  livingheaven [ Mon Mar 29, 2010 8:08 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

wait your getting the text as string, but how are you going to reuse that in a game ????


im confused

Author:  chrisbrown [ Mon Mar 29, 2010 8:24 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

The idea is that you can replace that string with some other data type. It would work just as well if you used ints or reals or something else.

code:
var name : string
var score : int
var aRandomArray : array 1 .. 10 of real

var stream : int
var file : string := "text.txt"

proc save
    open : stream, file, write
    write : stream, name
    write : stream, score
    write : stream, aRandomArray
    close : stream
end save

proc load
    open : stream, file, read
    read : stream, name
    read : stream, score
    read : stream, aRandomArray
    close : stream
end load



% Do this first
name := "PlayerName"
score := 5000
for i : 1 .. 10
    aRandomArray (i) := i
end for
save
%%%%%%%%%%%%%


% Then stop, remove the "Do this first section", uncomment the line below, and restart
% load

put name
put score
for i : 1 .. 10
    put aRandomArray (i)
end for



Follow the instructions. For comparison, after you're done, comment out "load" again, and see what happens.

Author:  livingheaven [ Mon Mar 29, 2010 8:37 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

thx

Author:  livingheaven [ Mon Mar 29, 2010 8:48 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

then how do u do auto save ?

is it like this


loop
if quit = true then
save
exit
end if
end loop

Author:  chrisbrown [ Mon Mar 29, 2010 9:50 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

Exactly. Note that if you close the program by any way other than the method that set quit to true (i.e. Turing's stop buttton or the window's "X" button) it won't save. Sorry if that's obvious to you; I've just had to help others with that problem.

Also, (again, sorry if obvious) quit is a reserved keyword, you'll need to use a different variable name.

Author:  livingheaven [ Mon Mar 29, 2010 10:24 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

oh ok , lol

i'll keep that in mind
thx for helping me out Very Happy
+ bits

Author:  livingheaven [ Mon Mar 29, 2010 10:26 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

for the close button, cant i just locate with
Mouse.Where (x,y,mb )
and then
if mb = 1 and it's in the red zone of the "x" then
save
exit
end if
?

Author:  copthesaint [ Mon Mar 29, 2010 10:33 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

Just want to send this out there too, the same idea in turing for saving and loading is almost the exact thing for using turing network class, so if anyone is trying to make an online game, get good at this first!

Now for what your doing, You may also want to make a system so that users cannot edit your program easily, Currently for my huge project I'm doing, and funny I saw this, I am making my classes for opening and closeing files. So anywho, make a system so that for example 1the number a9f could equal 1 and 43d could equal a. The better the system, the harder for a gamer to cheat.

Author:  chrisbrown [ Mon Mar 29, 2010 10:33 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

You could save when the mouse hovers over it, but as soon as you click it, execution halts, so Mouse.Where would never capture mb=1.

Author:  chrisbrown [ Mon Mar 29, 2010 10:40 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

@cop: look at the output of any file that has been 'write'd to. You may be doing a lot of unnecessary work. Also, a 1-1 mapping like that is about as bad as encryption systems go.

Author:  copthesaint [ Tue Mar 30, 2010 5:50 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

1: Turing is an OOP language, Did I ask for F****** help? WORRY ABOUT YOUR PROJECTS!
2: Your really stupid if you think I would do a 1-1 mapping. Just helping the guy start thinking about what he could do, get the train of thought going...
3: next time you see a post, just think about why the person may be posting it, and the general simplisity regaurding the person who started the thread.

4: Do you really think he would understand if I posted my encoder? *almost done first version

Author:  chrisbrown [ Tue Mar 30, 2010 6:28 pm ]
Post subject:  Re: RE:How do you Save a game and rerun it ??

1: OOP is suported. That doesn't mean it is well-implemented, or that it should be used.
2: That's what you posted, so that's what I based my statements on.
3: Given that it is a basic topic, I don't see how introducing encryption is going to be of any help.
4: No, so why are you bringing it up?

Before you start flaming me, maybe take some of your own advice and think about why someone is posting something. I was trying help by saving you some work. If you're looking for a challenge, or if you have a reason for doing so that I am unaware of, just say so.

Author:  copthesaint [ Tue Mar 30, 2010 7:31 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

2: Well maybe you shouldn't assume things then, should you? I was assuming nothing of the amount of ability, so I posted the most basic of which.
3: yes this is a basic topic, hence my refrence to 1:1 encription.

4: Brought it up just to let him know I have been working on this currently if he wants any help(Offering help, not assuming he needs help), by bringing it up, I am indirectly telling him I can help with anything elses related to this topic, that he may ask about. Its more of a deeper phycological thing.

5: I dont flame people unless they do somthing insulting to me directly. So qq!

6: Dont ****in help me unless I ask for it.

Btw, I noticed none mentioned to living,

eof (fileStreamID : int) : boolean

This function returns boolean; Eof returns true when you reach the end of a file, if you dont have this, and you reach past the end of the file, you will accually have to input the value instead of it reading it from the file.

Author:  USEC_OFFICER [ Tue Mar 30, 2010 8:06 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

1. Thanks for mentioning that, I completely forgot.

2. That would be more useful if he didn't know what was in the file.

3. You left out no. 1

4. Why is everybody making lists?

Author:  copthesaint [ Tue Mar 30, 2010 9:05 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

USEC_OFFICER, Dont answer in Lists, We were answering each statement in order of number, hence why there is no number 1. . .

Author:  USEC_OFFICER [ Wed Mar 31, 2010 11:38 am ]
Post subject:  RE:How do you Save a game and rerun it ??

It's a joke. However you did add no. 5 and 6.

Author:  copthesaint [ Wed Mar 31, 2010 5:16 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

5 and 6 were a split up of his last comment. I knew you were 'trying' to be funny, and it was funny how hard you were trying so in a round about way you made me laugh. I like how instead of talking, he Just flames me and ignores the thread. I on the other hand will not flame him, but I am p***ed with him for not repling, freakin donkey.

The Enemy has surrendered!
copthesaint + 1 Methodoxx 0

Author:  chrisbrown [ Wed Mar 31, 2010 6:12 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

I have better things to do with my time than argue on the internet. I'm sorry we don't agree. If it makes you feel better to think you won, go ahead and think that.

Author:  copthesaint [ Wed Mar 31, 2010 8:34 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

You Still gave me negative charma. + you dont have anything to argue about. Also quit f****** lieing. You are not sorry, and I bet you do have the time, since you are on about 3-4 times a day at least.

Author:  Dan [ Wed Mar 31, 2010 9:51 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

I have kicked copthesaint from this topic, hopefully we can return to helping livingheaven.

P.S. If any one else posts anything other then help in this topic they will also be kicked and there post will be removed.

Author:  TheGuardian001 [ Wed Mar 31, 2010 10:53 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

returning to the most recent question actually asked (saving on exit),

No, you can't really do that. You might be able to, as somebody suggested, save when somebody hovers over the close button (unless Mouse.Where only works inside the window, not sure on that one), however you wouldn't be able to do so when they clicked it.

If you intend to compile this program, Turing does provide a compile option to disable the close button (it'll still be there, it just won't do anything.) You could then include either a GUI button or a key combination that will save the game and exit the program.

There is no way to get the disable close button functionality when running the source code though, so this would only be a useful solution if you intend to compile.

Author:  livingheaven [ Sun Apr 04, 2010 12:34 pm ]
Post subject:  Re: How do you Save a game and rerun it ??

lol .. thx Very Happy

Author:  andrew. [ Sun Apr 04, 2010 7:59 pm ]
Post subject:  RE:How do you Save a game and rerun it ??

Why not have it autosave at certain intervals of time? e.g. save every 5 seconds.

Author:  apomb [ Mon Apr 05, 2010 9:15 am ]
Post subject:  RE:How do you Save a game and rerun it ??

That might create some unnecessary lag, but an autosave function might work, just at a convenient time, such as every time a point is scored (if this is that kind of game, i havent opened it) or when moving to a new area on a map (again, if it is that kind of game). Having it autosave during gameplay might also save unwanted values - for example, if you are just about to die, and bam, autosave - you die, get re-spawned just in time to be killed again... over and over.

Author:  andrew. [ Mon Apr 05, 2010 10:16 am ]
Post subject:  RE:How do you Save a game and rerun it ??

That's true. In that case, you can do what someone suggested above. Just disable the close button when compiling it, and have your own in-game exit button.


: