ID:157178
May 1 2010, 2:39 pm
|
|
Right now, I'm trying to use the If/Else stuff, to help detect if a player is new, or if they've been on the game before. What I'm thinking I want to do, is when you join the game for the first time, it puts your name on a txt file so that the game knows if you've joined before. Everything I've tried fails. Now that I'm out of options, I've decided to turn to you guys. You've helped me before, so I'm trusting the experienced developers here at at Byond.
|
A savefile.
Have a look through these: http://www.byond.com/ members/?command=search&type=resources&text=savefile There's also an entire chapter devoted to savefiles in the guide: http://www.byond.com/docs/guide/chap12.html As well as these reference docs: http://www.byond.com/ members/?command=reference&path=savefile Specifically, what you would want to be doing, is having a variable, which, set to default, is FALSE or 0:
mob/player/var/hasloggedinbefore=0
Which, upon logging in (this may be different for your file) you would put: src.hasloggedinbefore=1 (Assuming this is in something like Login().) Then you would make a savefile, var/savefile/F = new("players/[src.ckey].sav") and don't worry about the new() bit, as if there's one there already, it won't overwrite it. Then you would use something like:
F["hasloggedinbefore"] << src.hasloggedinbefore
to save, and:
F["hasloggedinbefore"] >> src.hasloggedinbefore
to load. For obvious reasons you want to load it before setting it to 1 and saving it. After you've loaded it you'll use something like this:
if(src.hasloggedinbefore)
which checks if it is true(non false) which, if saved as 1, it will be. Then you can do whatever you want to with them. |
In response to Cody123100
|
|
Cody123100 wrote:
oooooooor Thanks, but just gonna use vars and savefiles like Hiddeknight suggested. Thanks for posting though. |
In response to Magicmann
|
|
Problem with that is, you won't know if a player is new or not until they load up their mob. Which is fine too, it's just my way would let you know before then, so as soon as they logged in you could output something like
world<<"[src] has logged in for the first time!" Instead of having to check if they are a first time player every time they hit New or Load. |
In response to Cody123100
|
|
Your way would be wiped every time the server resets, unless you're saving a server-side list of all people who have logged into it. This however, would mean if someone logged into another server they would get the "never logged in before" treatment.
Also, your criticisms are invalid; Your way var/list/playersthatloggedin[0] My way: mob |
In response to Hiddeknight
|
|
Why not just use fexists() to see if they have an existing save or not? Seems like a good way of doing this to me.
|
In response to Nadrew
|
|
That would be better, assuming that he intends to use savefiles elsewhere anyway.
|
In response to Hiddeknight
|
|
Thank you all very much. You've helped me get a functioning save system up and running. Except, I've decided to go with the regular load, create, or leave options. Just have it showing an alert, with load, create, or leave. But the thing is, I'm coding it myself. Not using libraries. Just gonna use trial and error to fix mistakes. That's how I learned to code the DM language after all.
|
You could store a player's BYOND key in a list and then perform a check using if/else to see if they are/aren't in that list when they log in. Then add in the proc's that you want to occur.
In short read up on lists