ID:1131630
 
BYOND Version:498
Operating System:Windows 8 Professional with Media Center
Web Browser:Chrome 24.0.1312.52
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary: So well after a few hours of testing, and thinking i think this could be a huge bug? It's somewhat hard to explain, so, i'll try to be as clear as possible.

I was doing some code testing for something. Until i wrote this:

world/New()
..()
if(fexists("Data/Server.sav"))
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] >> global.MessageOfTheDay
WorldData["MaxPlayerCapacity"] >> global.MaxPlayerCapacity

world/Del()
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] << global.MessageOfTheDay
WorldData["MaxPlayerCapacity"] << global.MaxPlayerCapacity
..()


The issue with that code is that it didn't work properly, for some reason the first time i launch the world, file was being created with 2 empty lines. Fine, got created, but where's the content?
Then i joined for second time, but i couldn't join as i have a check (if PlayerAmount >= MaxPlayerCapacity, del src) but since the file was empty, MaxPlayerCapacity was null (as it couldn't be read). So then, i left and world/Del() got called.
After that second world/Del() stuff was being written but with null values.

So i went on SimpleChat and asked about it, it was strange. They told me to debug it. The code surpisingly worked fine if i ran the .dmb though Dream Daemon, but if i ran it though Dream Maker, the issue mentioned above would happen.

So then, after that, with Jemai1 we debugged it, we ended up with this:

world
New()
..()
log = "log.txt"
log << "Loading Savefile.."
if(fexists("Data/Server.sav"))
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] >> global.MessageOfTheDay
log << "\[Loaded] MessageOfTheDay: [global.MessageOfTheDay]"
WorldData["MaxPlayerCapacity"] >> global.MaxPlayerCapacity
log << "\[Loaded] MaxPlayerCapacity: [global.MaxPlayerCapacity]"
else
log << "Not Found."

Del()
var/savefile/WorldData = new("Data/Server.sav")
log << "Saving Savefile.."
WorldData["MessageOfTheDay"] << global.MessageOfTheDay
log << "\[Saved] MessageOfTheDay: [global.MessageOfTheDay]"
WorldData["MaxPlayerCapacity"] << global.MaxPlayerCapacity
log << "\[Saved] MaxPlayerCapacity: [global.MaxPlayerCapacity]"
sleep(20)
..()


Which worked pretty fine, but what?! It's the same code just with debugging.

After that we preceed to comment everything that's for debug. It started to fail again. So Jemai1 told me, "uncomment log = "log.txt"", i did it, and code started to work fine.

So we've got 'surprised' as log = "log.txt" doesn't affect to the loading / saving code. So i don't see why it would be affecting it.

So we tried putting after the else a new/savefile("Data/Server.sav") and removed the log = "log.txt", worked fine, again. But if i commented that new/savefile it wouldn't work again.

So we're reached the conclution, that for some reason, writing to file fails on world/Del() if you didn't access any file previously on world/New()

So this did work:

world/New()
..()
if(fexists("Data/Server.sav"))
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] >> global.MessageOfTheDay
WorldData["MaxPlayerCapacity"] >> global.MaxPlayerCapacity
else
new/savefile("Data/Server.sav") // See how this line affected everything else?
world/Del()
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] << global.MessageOfTheDay
WorldData["MaxPlayerCapacity"] << global.MaxPlayerCapacity
..()


but this didn't work:

world/New()
..()
if(fexists("Data/Server.sav"))
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] >> global.MessageOfTheDay
WorldData["MaxPlayerCapacity"] >> global.MaxPlayerCapacity

world/Del()
var/savefile/WorldData = new("Data/Server.sav")
WorldData["MessageOfTheDay"] << global.MessageOfTheDay
WorldData["MaxPlayerCapacity"] << global.MaxPlayerCapacity
..()


I'd like to note that, the code that "doesn't work", works on DD. But if you run it though Dream Maker, it won't work.

Numbered Steps to Reproduce Problem: Explained above.

Expected Results: It lets you to write on Del() without having to access a file previously on New()

Actual Results: Writing a savefile on Del() fails if you didn't access any file on New()

Does the problem occur:
Every time? Or how often? Everytime.
In other games? Yes.
In other user accounts? Yes.
On other computers? Yes.

When does the problem NOT occur? When you access any file on world/New()

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)

Workarounds: Access any file on world/New()