Ooops
February 27, 2021, 03:40:12 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
File Utilities
»
[bb] Simple File Save, File Load by wizzlefish [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Simple File Save, File Load by wizzlefish [ 1+ years ago ] (Read 568 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Simple File Save, File Load by wizzlefish [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Simple File Save, File Load
Author :
wizzlefish
Posted :
1+ years ago
Description :
This is my first entry to the code archives, and it will be very simple. This code saves the camera's x, y, and z location as integers, and loads it too.
Code :
Code: BlitzBasic
[
code
]
;Function SaveGame(camerahandle)
;Saves the game
;Perimeters:
;camerahandle - the handle of the camera you want to save the position of.
Function
SaveGame
(
camerahandle
)
;set up the screen
Cls
Locate
0
,
0
;let user choose what to save game as
filesave =
Input
(
"Save game as - "
)
filesave = filesave +
".dat"
;write files to dat file
fileout =
WriteFile
(
filesave
)
x =
EntityX
(
camerahandle
)
y =
EntityY
(
camerahandle
)
z =
EntityZ
(
camerahandle
)
;enter any other variables included in any games here.
x =
WriteInt
(
fileout
)
y =
WriteInt
(
fileout
)
z =
WriteInt
(
fileout
)
;for extra variables, use "WriteInt," "WriteString," and "WriteByte" accordingly.
;close file
CloseFile
(
fileout
)
End Function
;Function LoadGame(camerahandle)
;Loads a previously saved game
;Perimeters:
;camerahandle - handle of the main camera
Function
LoadGame
(
camerahandle
)
;set up the screen
Cls
Locate
0
,
0
;Let user load game
fileload =
Input
(
"Load file - "
)
fileload = fileload +
".dat"
;Open file for reading
filein =
ReadFile
(
fileload
)
;load info
x =
ReadInt
(
filein
)
y =
ReadInt
(
filein
)
z =
ReadInt
(
filein
)
;read all the other data you saved
;make sure it is in the same order you saved it as
;close the file
CloseFile
(
filein
)
;position camera
PositionEntity
camerahandle, x, y, z
SetUp
(
)
; some function to set up everything for your game.
End Function
;(c)2004 No Enemies Games (not really)
Comments :
N(Posted 1+ years ago)
1. Write the X/Y/Z positions as floats. That's how they're stored internally (maybe they're stored as doubles, but I sure as hell know that they aren't integers).2. WriteInt/Float/Short/etc. do not return anything of value. Don't bother doing 'x = WriteInt(file,val)', just make the call to the function and forget about assigning the variables a value.3. This code will not work. Plain and simple, you apparently didn't test it before uploading. Write functions take two arguments at minimum: stream and value. In your case, you're writing an integer without passing the value of the integer to the function.
wizzlefish(Posted 1+ years ago)
Yeah, nothing I do works. Oh well.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
File Utilities
»
[bb] Simple File Save, File Load by wizzlefish [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal