ID:263567
 
I made a title screen with the background and tile and 3 buttons (new game, continue, delete) with the following code:


world
view = 5
turf
icon = 'Turfs.dmi'
grass
icon_state = "grass"
background
title
icon = 'title.png'
density = 1
black
icon_state = "black"
obj/New
icon='newgame.png'
Click()
usr.loc = locate(2,2,2)
obj/Load
icon='loadgame.png'
Click()
Read(var/savefile/F = new())
obj/Delete
icon='delete.png'
Click()
Write(var/savefile/F = del())
mob/Logout()
Write(var/savefile/F = new())


...I got these errors:



main.dm:24:error:var/savefile/F:undefined var
main.dm:28:error:var/savefile/F:undefined var
main.dm:28:error:del :empty argument not allowed
main.dm:28:error::missing expression
main.dm:30:error:var/savefile/F:undefined var


what's wrong? What I want to do (you probably know) is to make 3 buttons on the title screen. New game, continue and delete. I've seen naruto games do it and stuff so I know it can be done. Did I misstype something or is there a better way to do this.
Carved in Shadows wrote:
I made a title screen with the background and tile and 3 buttons (new game, continue, delete) with the following code:
obj/New
icon='newgame.png'
Click()
usr.loc = locate(2,2,2)
obj/Load
icon='loadgame.png'
Click()
Read(var/savefile/F = new())
obj/Delete
icon='delete.png'
Click()
Write(var/savefile/F = del())
mob/Logout()
Write(var/savefile/F = new())


Well, first let's go over the path names. Don't use obj/New, because there's already a New() proc and this is gonna screw you up. Change it to obj/NewCharacter or such.

Now for the individual problems:

obj/Load
icon='loadgame.png'
Click()
Read(var/savefile/F = new())

<font color="red">> main.dm:24:error:var/savefile/F:undefined var</font>

You're doing three things quite wrong here.

  • If you set up a savefile with no filename in new(), it is a runtime-only file and will not be loaded from or saved to anywhere.
  • You have to set up a var before sticking it in the proc's arguments, not during. You could put new/savefile() in there directly, and just get rid of F altogether, or initialize F before calling Read().
  • Calling Read() here is actually not the right thing to do anyway; that'll call obj/Load/Read(), not mob/Read(), and what you obviously want to do is load a mob from the savefile. You won't be calling Read() directly when doing that, either.

    So really, you need to look up how to use savefiles.
obj/Delete
icon='delete.png'
Click()
Write(var/savefile/F = del())

<font color="red">> main.dm:28:error:var/savefile/F:undefined var
main.dm:28:error:del :empty argument not allowed
main.dm:28:error::missing expression</font>

Some of the same problems are here, but there are brand new ones. As the compiler told you flat-out, you can't call del() without telling it what to delete. No, this does not tell it to delete a savefile. You may notice it doesn't say anywhere which savefile to delete, and even so you'd need to use fdel() for that. del() is for deleting objects in memory, not files.

Also, it's clear that you shouldn't be calling Write() here at all, since your goal is to delete, not save. And to save, you shouldn't be calling Write() directly.

mob/Logout()
Write(var/savefile/F = new())

<font color="red">> main.dm:30:error:var/savefile/F:undefined var</font>

Again the F var isn't initialized properly, and you shouldn't be calling Write() directly.

Lummox JR
In response to Lummox JR
Thank you very much, but... It was hard to make heads or tails of exactly what to do to make this work. For example, you said what was wrong with read() and write() (I think) and then later said not to use them. (BTW, Where is a good place to learn to use savefiles). Can you post the fixed code? (maybe with some helpful comments?)
In response to Carved in Shadows
You should read the DM Guide before proceeding, including the savefiles chapter..
In response to Kaioken
Ok... Here's a more educated guess then... what about this code:

var/savefile/F = new("players.sav")

obj/NewGame
icon='newgame.png'
Click()
usr.loc = locate(2,2,2)
obj/Load
icon='loadgame.png'
Click()
Read(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))


mob/Logout()
Write(F)
//store coordinates
F << x
F << y
F << z
//store variables
..()


It runs, but when I click 'Load' then the square I click goes away... the end
In response to Carved in Shadows
When you run Move([stuff]), you're actually calling src.Move([stuff]). src in this case is the obj/Load button, since Click() belongs to it. Instead try player.Move(), where player is a variable referring to the player's mob. usr might work here, but usr can sometimes break when saving and loading things, so I'm not entirely sure.
In response to Jon88
Duh!!!! I'm soo dumb. Obviously the turf was moving instead of the player. I simply changed it to 'usr.loc = locate(saved_x,saved_y,saved_z)'

thank you so much!
In response to Carved in Shadows
Carved in Shadows wrote:
Ok... Here's a more educated guess then... what about this code:
var/savefile/F = new("players.sav")

obj/NewGame
icon='newgame.png'
Click()
usr.loc = locate(2,2,2)
obj/Load
icon='loadgame.png'
Click()
Read(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))

mob/Logout()
Write(F)
//store coordinates
F << x
F << y
F << z
//store variables
..()


Well, that isn't really an educated guess because it's clear you did not yet educate yourself on how to use savefiles. You're just taking snippets of code you've seen on the rest of the forums and pasting them in there. That F<<x stuff goes inside Write(), not after. It's also obvious based on the comments that the ..() call you made was meant to go inside the Read() proc, not outside. So you're not only copying and pasting code you don't understand, but because you don't understand it, you're pasting it incorrectly. And as I said, you should not be calling Write() directly. That isn't how savefiles are generally used.

You're also using the same savefile for all players. If one player saves, they'll overwrite all the others.

What you need to do in each save/load proc is first open up the correct savefile for that player, and then save or load their entire mob using the << or >> operators (respectively). Those will call Read() and Write() for you, and the code you've now pasted in underneath those routines, should instead go in them.

But before you attempt to do any of that, go to the DM Guide and actually read the chapter on savefiles. Once that gives you a pretty good grasp of what to do, you'll know how to proceed.

Lummox JR
In response to Lummox JR
Aye, also don't forget the holy DM Reference (press F1 in Dream Maker) which also has useful info on savefiles.