ID:975306
 

what better way to do the functions to save and log out?

I use / mob? / client?
how to save only the log out?
currently use a while loop every x minutes, and it really bad
/proc/SaveMob(mob/x)
if(!x){CRASH("No mob sent to SaveMob(x.type)");return}

if(fexists("Savefiles/Players/[copytext(x.key,1,2)]/[x.key].SAV")){fdel(S);return}
var/savefile/S = new("Savefiles/Players/[copytext(x.key,1,2)]/[x.key].SAV")
S["mob"] << x
S["sxyz"] << list2params(list(x.x,x.y,x.z))
x<<"You saved your game"

/proc/LoadMob(mob/logincharacter/x)
if(!x){CRASH("No mob sent to LoadMob(x.type)");return}
if(!fexists("Savefiles/Players/[copytext(x.key,1,2)]/[x.key].SAV")){src<<"No file found";return}
var/savefile/S = new("Savefiles/Players/[copytext(x.key,1,2)]/[x.key].SAV")
var/mob/player/newmob = S["mob"]
var/mob/oldmob=x

x.client.mob=newmob
x.loc=locate(params2list(S["sxyz"]))

You might want to change some mobs definitions to fit your game.

This save/load is designed to work with a mob for the login screen, to difference them from real players.

you might want to define the following mobs:
mob/logincharacter
mob/player

It is pretty basic and yoou will have to adapt it to what you need.

If you want to save only on logout, you must do the following:
mob/player
Logout()
SaveMob(src)
..()
I want to give you one major good tip, if you can actually do a save in which you write only text variables for players and you are able to restore the player to the same stat at mob/Login() using only those text variables, then your save files will be smaller and more efficient.

Per http://www.byond.com/docs/guide/chap12.html
if you do something like:
mob/Write(savefile/F)
//store coordinates
F << x
F << y
F << z
//store variables
..()
mob/Read(savefile/F)
var {saved_x; saved_y; saved_z}
//load coordinates
F >> saved_x
F >> saved_y
F >> saved_z
//restore variables
..()
//restore coordinates
Move(locate(saved_x,saved_y,saved_z))


Where you sequentially save each variable in the same order (or you can use an associated list by doing F["variable name"] <<variablename but whatever.) for both read and write, then what will happen is that you can save only the variables you NEED to save, maybe the name of the hairstyle your character has on, and then do a switch() statement on login and add that overlay to your character, rather than saving the bloody hair icon itself.

In addition, you only need to save every X minutes if your server has a tendency to crash, if it doesnt crash then you can save on client/Del() rather than on a periodic basis. If your server does crash, then saving every mob at once might still be difficult for the server, be sure to set background = 1 on the save loop and if possible instead of saving everybody at the same time, run a for() loop of logged in clients with a nice 1 second sleep between saves, that'll help.
thx... look now
Well if we go on performance saving, nothing can do better than MySQL Queries. But that's way more complex and I doubt he could implement that to the game.

I don't think Write and Read are the best ways to do so, some time later on the game he will need to save other types of vars, and whatnot some list, overlays, icons. Lists are easy to not save by converting them to a parameter string, he would also select what variables to save, and what vaiables to not to, Write selects that for you, by onl excluding the constant vars and tmporal ones.

If it is gonna be a small project then you're more than fine with the Write() and Read() built-in procs, but if it is gonna be big you might want to make your own behavior.
Good to know, I know Mysql, I will research your operation with byond...
thx

still try the above examples.
In response to Neo Rapes Everything
Neo Rapes Everything wrote:
Well if we go on performance saving, nothing can do better than MySQL Queries. But that's way more complex and I doubt he could implement that to the game.

You assume to much, we have a library for MySQL and it works OOTB.
what library? OOTB?
Sigh check the resources section it's under the Developers menu item.. or click here

OOTB - Out of the box.
The MySQL library isn't actually called MySQL it's called DB - http://www.byond.com/developer/Dantom/DB
In response to DvK87
If you're suggesting what I think you're suggesting (a big list of F[var]<<var), then I have one major good tip for you.

tmp variables
I'm aware of temp variables, Im assuming OP is not diligent or knowledgeable of his own code (likely a rip). Rather than have him go back and mark variables as temporary, at this point he is better off identifying the variables that need to be persistent.
well, I know how to code in java, and have already used mysql, but I don't know much, create charts, insert, edit etc, that's easy but I have some doubts.

for example in Byond is there some rule about how many fields on the chart or may I do as I please? for example: a mob field, that would receive the vars mob and the x,y,z, just that would work? and a Byond username as primary key?

I'll try to do somthing here, connect with the database and see what happens.
thx


Can you please make sure that sintax are correct? Because if it is correct, i'll see my "BD", but the password are correct, the bank's name, everything, i don't see the reason why that's don't work, only if the problem are on the sintax

result: Could not find the specified module

            var/DBConnection/dbcon = new()
dbcon.Connect("dbi:mysql:mybd:127.0.0.1:3306","root","")
if(!dbcon.IsConnected())
usr << dbcon.ErrorMsg()