ID:93077
 
Not a bug
BYOND Version:464
Operating System:Windows XP Pro
Web Browser:Firefox 3.6
Applies to:DM Language
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Duplicates:id:104235
text2file() Add's an end line character at the end of the text written to the file.
When using text2file I would like it to save exactly how I intended for it to save instead of having the break code.
SaveChar()
if(!ingame) return
var/srcsave = "players/[copytext(src.key,1,2)]/[src.key].txt"
if(fexists(srcsave))
fdel(srcsave)
text2file("name=[src.name]&hp=[hp]&maxhp=[maxhp]&level=[level]&mp=[mp]&maxmp=[maxmp]&exp=[exp]&maxexp=[maxexp]&expt=[expt]&patt=[patt]&pdef=[pdef]&matt=[matt]&mdef=[mdef]&gold=[gold]",srcsave)


When converting the params into a list the last number, in this case gold, is bugged because of the \n character. When attempting to add a number to the gold that has skipped the number check because of the character it creates a bug, because you cannot add a number to text. I am not sure how to filter it because if you use \n in dm when trying to filter, it won't work. and if you copy / paste the character \n makes, dm won't compile.

This is the bring-back-into-vars proc just in case.
LoadChar()
var/srcsave = "players/[copytext(src.key,1,2)]/[src.key].txt"
if(fexists(srcsave))
var/Container[] = params2list(file2text(srcsave))
var/v
for(v in Container)
if(!v) continue
if(v in src.vars)
if(text2num(Container[v]))
Container[v] = text2num(Container[v])
if(Container[v] == "0")
Container[v] = 0
src.vars[v] = Container[v]
world<<"<small><b>[html_encode(src)] has rejoined us!</b></small>"
else
alert("No savefile found!")
return


Workarounds: add a blank non-existing param at the end, let that one get messed up.
This is actually the intended behavior, and for backwards-compatibility reasons we can't really change it at this point.

You can, however, suppress the appended newline by using the \... macro, eg:
text2file("foo\...","myfile")
text2file("bar","myfile")

I have added this note the text2file reference entry as well.