ID:1047383
 
(See the best response by Jemai1.)
mob
Login()
..()
var/savefile/sa=new("player")
sa>>banned
//rest of login...

verb
Ban(mob/them in world)
them.banned=1
var/savefile/sa=new("player")
sa<<them.banned
del them


Problem description:
When I run my project on DM, once the Login hits the savefile, it fails and crashes the rest of Login(). Then when I host on Daemon, it works perfectly fine and the savefile also works. However, some people get the crash while others work fine, and it seems to always be the same people either working or failing. Also, it provides no runtime error. And if I change the brackets to src, or leave it blank, it doesn't work. Changing the brackets to key has the same result as giving it a name. Why does the savefile crash? And why only some people?
Best response
Why are you using a single savefile for everyone? If it is a single player game played locally, that's fine. If not, it is best to have a savefile for each person.

Anyways, you should check if the file "player" exists with fexists proc. If it doesn't exist, there is nothing to load/read.
The savefile works when I host Daemon, but crashes only some people. That's what I don't understand. Also, what did you mean by "change having a single savefile for everyone" to "have a savefile for each person?" And how do I make that change?
You'll want to check if the file exists which Jemai1 suggested

if(fexists("player"))
//continue to load
else
//create one


If this save file is for each player it'll be overwritten as it would belong to each player (kind of silly that you did that :) )

So you would want to give the save file a good name using the players ckey it great as ckey cut's out spaces and other naughty text!

var/savefile/sa=new("player/[src.ckey].sav")//. sav or not .sav .whateveryouwant
I tested using fexists() and it does exist, the file is there.

Also, that method with using ckey didn't change anything. I'm still receiving the exact same problems.
It was not a solution but an example.
The file "player" is most likely corrupted from your previous mess. Delete it first.

Always check for the existence of the file before reading it. In addition, do not read a blank savefile.
In response to Jemai1
Jemai1 wrote:
The file "player" is most likely corrupted from your previous mess. Delete it first.

Always check for the existence of the file before reading it. Do not read a blank savefile.

Although you are more than likely correct, one would of assumed he went with the ckey process so it shouldn't of even looked at the player file, but then people are susceptible to copy and pasting especially around here.
In response to A.T.H.K
A.T.H.K wrote:
> if(fexists("player"))
> //continue to load
> else
> //create one
>


It doesn't make sense to create a new savefile upon loading. It should only be done on save. ;)
In response to Jemai1
Correct, although it was just an example.
In response to A.T.H.K
Of course. We just don't want him to do the same so I pointed it out.

@Zerok Kaiba
I just noticed that this is a ban system. The actual savefile of players might be in a different place. Could you post the whole thing?
In Login(), after what I displayed in the 1st post, it just checks the banned variable with if(). That's the entire ban mechanics.
//This 1 is done to save the number of kills a usr has\\
// use this concept to make ur ban save system\\

mob/var/kills=0

mob
Read(var/savefile/F)
..()
F >> usr.kills //loads usr.kills

Write(var/savefile/F)
..()
F << usr.kills //saves usr.kills

proc
loadgame()
if(fexists("Saves/[src.key].sav"))
var/savefile/F=new("Saves/[src.key].sav")
Read(F) //loads F which is the savefile
else
..()
savegame()
var/savefile/F=new("Saves/[src.key].sav")
Write(F) //saves F which is the savefile


mob
Login()
usr.loadgame()


mob
Logout()
usr.savegame()
In response to Zerok Kaiba
Zerok Kaiba wrote:
In Login(), after what I displayed in the 1st post, it just checks the banned variable with if(). That's the entire ban mechanics.

I know. What I'm interested at is the save/load system.
In response to Sers000
Sers000 wrote:
>
>
>
> //This 1 is done to save the number of kills a usr has\\
> // use this concept to make ur ban save system\\
>
> mob/var/kills=0
>
> mob
> Read(var/savefile/F)
> ..()
> F >> usr.kills //loads usr.kills
>
> Write(var/savefile/F)
> ..()
> F << usr.kills //saves usr.kills
>
> proc
> loadgame()
> if(fexists("Saves/[src.key].sav"))
> var/savefile/F=new("Saves/[src.key].sav")
> Read(F) //loads F which is the savefile
> else
> ..()
> savegame()
> var/savefile/F=new("Saves/[src.key].sav")
> Write(F) //saves F which is the savefile
>
>
> mob
> Login()
> usr.loadgame()
>
>
> mob
> Logout()
> usr.savegame()
>


No usr in procs. In addition, the kills var will be saved/loaded automatically since it is neither tmp, const, nor global.
System? I've shown you everything to do with the savefile. Nothing else in my entire codes uses savefiles. I just save the banned variable to the savefile, then load in Login().
Is banned a list? your code is terrible if you are trying to do a ban system...
Banned is a single variable. Also yeah, if I could make a good ban system I wouldn't be here.
Those libraries are showing how to make a list to ban players. I can do that. The problem is the savefile. I have a Boot() verb which bans a player for a single round. My Ban() verb needs savefiles so that it actually lasts until either I unban or wipe the rsc.
Page: 1 2 3 4