Posted: 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 ?
Any help would be great.
Sponsor Sponsor
USEC_OFFICER
Posted: 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.
livingheaven
Posted: 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 ..... =.=
USEC_OFFICER
Posted: 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.
chrisbrown
Posted: 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.
livingheaven
Posted: 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
livingheaven
Posted: 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
chrisbrown
Posted: 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.
Sponsor Sponsor
livingheaven
Posted: Mon Mar 29, 2010 8:37 pm Post subject: Re: How do you Save a game and rerun it ??
thx
livingheaven
Posted: 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
chrisbrown
Posted: 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.
livingheaven
Posted: 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
+ bits
livingheaven
Posted: 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
?
copthesaint
Posted: 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.
chrisbrown
Posted: 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.