ID:1205906
 
Keywords: code, function, help, login, save
(See the best response by Solomn Architect.)
I found this code online because i'm very unoriginal, and i'm a beginner.

however, when attempting to apply it to my rpg, it didn't want to work.

Can any of you figure out what's wrong with it?

Code:
mob/player/proc
CreateNewCharacter()
var/char_name = input("New character", null, "What is the character's name?") as text
SaveCharacter(char_name)
return char_name
SaveCharacter(char_name)
var/savefile/F = new("players.sav")
var/safe_name = ckey(char_name)
F.cd = "/[ckey]/[safe_name]"
F["full_name"] << char_name
mob/player/Login()
var/savefile/F = new("players.sav")
F.cd = "/[ckey]"
var/list/characters = F.dir
var/newCharacterChoice = "<Create new character>"
var/list/menu = new()
menu += characters
menu += newCharacterChoice
var/result = input("Who do you want to be today?", null, "Choose a character or create a new one") in menu
if (result == newCharacterChoice)
name = CreateNewCharacter()
else
F.cd = "/[ckey]/[result]"
F["full_name"] >> name
return ..()
mob/player/proc/DeleteCharacter()
var/savefile/F = new("players.sav")
F.cd = "/[ckey]"
var/list/characters = F.dir
var/list/menu = new()
menu += characters
var/result = input("DELETING a character", null, "Which character do you want to delete?") in menu
if (result)
F.cd = "/[ckey]"
F.dir.Remove(result)


Problem description:
it's supposed to bring up a prompt that will allow you to choose either create a new character, load a character, or delete a character. I get no errors when compiling, but no promp will show when running a test.
Well I think it is because you have the procs defined for mob/player and not mob.

So try this:

mob/proc/CreateNewCharacter()

// and

mob/proc/SaveCharacter()

// and

mob/Login()

// and

mob/proc/DeleteCharacter()


Instead of

mob/player/proc/CreateNewCharacter()

// and

mob/player/proc/SaveCharacter()

// and

mob/player/Login()

// and

mob/player/proc/DeleteCharacter()


That should work. The biggest problem in the code you provided is that mob/player/Login() isn't really called when the player logs in, mob/Login() is called.
Try adding:

world
mob=/mob/player


That will make the default mob-type a mob/player so that when clients (players) connect to your game they will be given a mob/player which will have to login and thus use your login() procs.

The risk with doing it Nailez's way is that -every- mob (including NPCs) will be given those procs, and I suspect your NPCs could care less about creating new characters or saving. If anything it might add complications later.
Everything is defined under /mob/player , but on login by default the player is just a /mob.

To change this, define the world's mob variable to the /mob/player path. This sets the default mob type for clients.
Best response
The biggest problem isn't the fact that it doesn't work without /mob/player, it's the fact that you're not taking the time to really master the language before trying to tackle a game, especially something as complex as an RPG. Let's just say that even quite a few veteran developers don't even get into that genre. The chances of it just turning into a big mess are very high. I know first hand.

That isn't to say that I don't admire your courage, however.
I thought of saying exactly the same Solomn Architect, but I've tired of saying this to every post I see in "Newbie Developers" using copied code, and decided to try and help answer this problem rather than the "biggest" problem with it. =)