ID:159368
 
var
savefile/S
proc/Proc1()
S=new("players/CharSaves/[name]")
N=ToParams(list(name,100,100,1,0,50,50,50,50))
S["stats"]<<N
proc/Proc2()
S=new("players/CharSaves/[A]")
var/N
S["stats"]>>N

Variable S is global. In Proc1 I make new savefile using global var and save some information. Later in Proc2 I try to load that information, but it ends up with null. Then I checked and savefile was 0 bytes in size. Once I closed world (DreamSeeker) information been written to savefile. Why?

P.S.1 If you wonder why I use global var, then I'm just too lazy to type var/savefile/S everytime
P.S.2 Before you start whining, [A] and [name] are equal
You have to give the files an extension (.sav)
In response to Falacy (#1)
Falacy wrote:
You have to give the files an extension (.sav)

That's not even true.


I put the exact code to in a test game and it worked fine. I don't know why it would fail for you.
In response to T3h P3ngu1n (#2)
T3h P3ngu1n wrote:
I put the exact code to in a test game and it worked fine. I don't know why it would fail for you.

That exact code wouldn't even compile by itself.

And after some testing:
A. It appears you don't need file extensions anymore.
B. The problem is because you have S as a global variable, guess you're going to have to be less lazy.

mob/verb/Proc1()
var/savefile/S=new("players/CharSaves/Save")
var/N=list2params(list("name",100,100,1,0,50,50,50,50))
S["stats"]<<N
world<<N;world<<"Saved"
mob/verb/Proc2()
var/savefile/S=new("players/CharSaves/Save")
var/N
S["stats"]>>N
world<<N;world<<"Loaded"

Modified for my experiments
In response to Falacy (#3)
I had S as a global var and it still worked for me. I really don't see how that would affect it.
In response to T3h P3ngu1n (#4)
T3h P3ngu1n wrote:
I had S as a global var and it still worked for me. I really don't see how that would affect it.

I assume its because the system doesn't close the file between verbs/procs when its referenced in a global variable.
In response to Falacy (#5)
Falacy wrote:
T3h P3ngu1n wrote:
I had S as a global var and it still worked for me. I really don't see how that would affect it.

I assume its because the system doesn't close the file between verbs/procs when its referenced in a global variable.


Yeah I had was thinking that when he had posted it, but when I tried it, it worked just fine. The savefile was created and had the information in it right away when the proc was ran on my end. The version of BYOND might have something to do with it. I'm using the latest version of BYOND availble for download. Which version is Ripiz using?
In response to T3h P3ngu1n (#6)
I use newest too (438.1014). Thanks for replies, guess I will have to be less lazy...

Thanks again

EDIT: After changing variable to local, not global it started to work fine. Thank you
In response to Ripiz (#7)
Ripiz wrote:
I use newest too (438.1014). Thanks for replies, guess I will have to be less lazy...

That's not the newest. 440.1016 is even available on the official download page.
In response to Falacy (#8)
Huh? Hm.. Weird, I don't get any notify about available update... Guess I have to download it manually, but I changed code already so I'm too lazy to try global variable again