ID:140272
 
Code:
These are the Vars for Mob(player)
mob/Stat()
statpanel("Character") //Creates a new Tab for stats
stat(usr)
stat("Coords - [x],[y],[z]",)
stat("Name:",name) //Every stat() under that will go in the statpanel above
stat("Village:",Village)
stat("Element:",Element)
stat("Rank:",rank)
stat("Yen: [Yen]$")
stat("Level:",Level)
stat("Exp:","[usr.exp] / [usr.max_exp]")//Same with HP and MP.
stat("HP:","[hp]/[maxhp]")
stat("Chakra:","[Chakra]/[maxchakra]")
stat("Tai:",tai)
stat("Nin:",nin)
stat("Gen:",gen)
stat("Defense:",defense)
statpanel("Inventory") //MAkes a new stat panel called inventory

stat(contents) //this is where the contents will go




mob
var
Village //Village used in
Element
Level = 1
defense = 100 //Defense of Character
maxhp = 5000 //Max HP, for when healing (so as not to go over)
hp = 5000 //HP for when getting hurt/dying
maxchakra = 2500 //Max MP for recovering MP
Chakra = 2500 //MP for how much player has
equip = 0
input
SaveSlot
Yen = 100000

//---------------------------------------------------------\\
mob/Login()
world << "<b><font face=tahoma><font size=-1><font color=white>[usr] Logs in"
icon="BaseT.dmi"
icon_state=""
winset(src, "outputwindow.output", "style='icon{width:32;height:32;}';")
usr<<sound('closer.ogg',0)//Play this sound over and over again
usr.loc = locate(9,9,4)//When the mob logs in, take him to this point

mob
Logout()
world << "<font color=white>[usr] has logged out"
src.Save()
..()
sleep(5)
del(usr)



turf
New
icon='player.dmi'
icon_state="New"
density=1
mouse_opacity=2
layer=10
Click()
if(fexists("Playersaves/[usr.ckey].sav"))
alert("There is already a save")
goto REMOVE
REMOVE
switch(input("Delete current save?","Delete?") in list ("Yes","No"))
if("Yes")
usr.Delete_Mob()
if("No")
usr.loc = locate(9,9,4)




turf
Load
icon='player.dmi'
icon_state="Load"
density=1
mouse_opacity=2
layer=10
Click()
var/savefile/F=new("Playersaves/[usr.ckey].sav")
usr.dir = SOUTH
Read(F)
var/newX
var/newY
var/newZ
F["lastx"] >> newX
F["lasty"] >> newY
F["lastz"] >> newZ
usr.loc = locate(newX,newY,newZ)





mob
proc
Save()
var/savefile/F=new("Playersaves/[src.ckey].sav")
src.Write(F)
F["lastx"] << src.x
F["lasty"] << src.y
F["lastz"] << src.z
world << "<b><font face=tahoma><font size=-1><font color=red>[usr] Logs out"

Load()
var/savefile/F=new("Playersaves/[usr.ckey].sav")
usr.Read(F)
var/newX
var/newY
var/newZ
F["lastx"] >> newX
F["lasty"] >> newY
F["lastz"] >> newZ
usr.loc=locate(newX,newY,newZ)

Delete_Mob()
if(fexists("Playersaves/[usr.ckey].sav"))
switch(alert(usr, "Are you sure.", "Character Deletion", "Yes","No"))
if("Yes")
usr<<"<font color=red>Accessing server database...</font>"
var/savefile/F = new("Playersaves/[usr.ckey].sav")
usr<<"<font color=red>Accessing save file...</font>"
sleep(1)
usr.Read(F)
sleep(1)
fdel("Playersave/[usr.ckey].sav")
icon='player.dmi'
icon_state="blank"
usr<<"<font color=red>Save deleted.</font>"
usr.loc = locate(49,9,4)
goto RENAME
RENAME
src.name = input("Your characters name","Set name") as text
if(length(src.name) >= 16)
alert("Sorry, no more characters than 15 characters!")
goto RENAME
if(length(src.name) <= 2)
alert("Sorry, no less than characters than 2 characters!")
goto RENAME
usr.name = name
usr.loc = locate(49,9,4)
if("No")
usr<<"Try load instead."
usr.loc = locate(9,9,4)
else
alert("No savefile found in this slot!")
usr.loc = locate(49,9,4)


Problem description:


Sooo Guys I have this nice little Code "WorkinG" So far.

Its about a New,Load,Delete,Save System

What I need is: A Code which loads the vars such as HP, Chakra whatever ( Yes it is a Naruto game but thank god its no rip)

I have the Locations Working But When I Load the Game there is No saved Icon or the stats are like at the beginning when you create a new character

If you need any piece of Information Just Post it ^^
Im looking forward to your Help and I need this to start working on

If you want to commission people to do work for you, the place for that is Classified Ads. Code Problems is where you go if you need help fixing a piece of code.

That said, one major issue is that you are saving/loading improperly. All logic related to saving and loading go in the Write() and Read() procs, and the actual saving and loading is done by F << mob and F >> mob. Like so:

client
New()
if(fexists("[key].sav"))
var/savefile/F = new("[key].sav")
F["mob"] >> mob
..()

Del()
var/savefile/F = new("[key].sav")
F["mob"] << mob

mob
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
Read(var/savefile/F)
..()
loc = locate(F["x"], F["y"], F["z"])



Additionally, you should not be using goto. At all. Ever. For looping, the appropriate constructs are for() and while(). Of course, looking closer, you have it in other places which make absolutely no goddamned sense. You NEED to remove every single instance of goto in your project.

Furthermore, you should not be using usr in procs. If src isn't correct, then the proc should take an argument which is.
In response to Garthor
First of I would Like to say thank you for taking Your Time to help me.
I appreaciate it.

Now I would Like to Explain myself.
I think the main problem is that i dont understand a bit of what your trying to tell me .
Im seriously trying but cant.
Dont judge me for that in the future.


Now what I need is you to make that code work.
And if you cannot do that because this is the wrong section then please take a look at this: http://www.byond.com/developer/forum/?id=741981

Like I said, I need you to write that code your trying to explain to me since only you replyed. You are my only hope right now.

I need a finished code.
Call me lazy, call me dumb but thats what I need.


In response to Vokicpower
In response to Vokicpower
well you could always try this :P

mob/var/variables = ""
mob
Write(savefile/F)
..()
F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z
src.variables = list2params(src.vars)
F["Vars"] << src.variables

Read(savefile/F)
..()
F["X"] >> src.x
F["Y"] >> src.y
F["Z"] >> src.z
F["Vars"] >> src.variables
var/list/vars_list = params2list(src.variables)
for(var/v in src.vars)
v = vars_list[v]

mob/proc/Load()
if(fexists("saves/[copytext(src.ckey,1,2)]/[src.ckey]"))
var/savefile/F = new("saves/[copytext(src.ckey,1,2)]/[src.ckey]")
src.Read(F)

mob/proc/Save()
var/savefile/F = new("saves/[copytext(src.ckey,1,2)]/[src.ckey]")
src.Write(F)

mob/Del_Save()
var/savefile/F = new("saves/[copytext(src.ckey,1,2)]/[src.ckey]")
fdel(F)
src<<"Save Deleted"
In response to Masschaos100
That would not work. Even if the glaring errors were corrected, it would still not work.

Please know what you are doing before attempting to help others.
In response to Garthor
sry but i pressed tab before i could finish then i pressed space >.>
In response to Masschaos100
Glad we settled that. Now it just doesn't work, which is an improvement over spectacularly failing if it WERE to work.

Again, same point as before. If you don't know what you're doing, attempting to help other people just clutters the forums at best and reinforces horrible practices at worst.
In response to Garthor
it does work :P
In response to Masschaos100
It only works in the sense that it is doing the default action of Write() and Read(). And saving x,y,z, which is something I've already posted in an example here.

Your mucking around with the vars list was pointless and - if it actually worked - would cause spectacular failure. There are a number of variables which you don't want to save, which is why they are NOT SAVED, and attempting to circumvent that in the general case will lead to major issues.

Additionally, because you've saved wrongly (by calling Write() and Read() directly) the whole thing is prone to more spectacular failures, of the nearly-impossible-to-diagnose kind. This is the absolute most insidious kind of wrong advice: it mostly works, especially in simple cases, so people will gladly accept it and then go on to spread it. It EVENTUALLY will break and cause major problems, but by then there's a half-dozen more people who have copied them and are set up for failure themselves. Abusing usr is another bit of advice that I would put in this category.

So, again, [i]stop giving advice if you don't know what you are talking about[/i].
In response to Garthor
So guys Can we Start talking about the topic again And Give me some real advice with which I can Now improve that save Code?
In response to Garthor
Garthor wrote:
That would not work. Even if the glaring errors were corrected, it would still not work.

Please know what you are doing before attempting to help others.

Comedy gold. I missed you Garthor.
In response to Vokicpower
I already gave you the advice that you need. I chose to ignore your request for me to do everything for you because it was thoroughly unreasonable.
In response to Garthor
Okay then lemme ask like this :

Can Anyone tell me what Code I need to save Player stats and not just the location ?
And If I have this code in this topic already explain to me where it is ? and/ or what I need also ?

In response to Vokicpower
In response to Garthor
Now I have this :

mob/Login()
world << "<b><font face=tahoma><font size=-1><font color=white>[usr] Logs in"
usr<<sound('closer.ogg',0)//Play this sound over and over again
usr.loc = locate(9,9,4)//When the mob logs in, take him to this point

mob
Logout()
world << "<font color=white>[usr] has logged out"
..()
sleep(5)
del(usr)


turf
New
icon='player.dmi'
icon_state="New"
density=1
mouse_opacity=2
layer=10
Click()
if(fexists("Playersaves/[usr.ckey].sav"))
alert("There is already a save")
goto RENAME
RENAME
src.name = input("Your characters name","Set name") as text
if(length(src.name) >= 16)
alert("Sorry, no more characters than 15 characters!")
goto RENAME
if(length(src.name) <= 2)
alert("Sorry, no less than characters than 2 characters!")
goto RENAME
usr.name = name
usr.loc = locate(49,9,4)






turf
Load
icon='player.dmi'
icon_state="Load"
density=1
mouse_opacity=2
layer=10
Click()
var/savefile/F=new("Playersaves/[usr.ckey].sav")
Read(F)


mob
verb
SaveNow()
var/savefile/F = new("Playersaves/[src.ckey].sav")
Write(F)
alert("Done")




client
New()
if(fexists("Playersaves/[key].sav"))
var/savefile/F = new("Playersaves/[key].sav")
F["mob"] >> mob
usr<<sound('closer.ogg',0)//Play this sound over and over again
..()


Del()
var/savefile/F = new("Playersaves/[key].sav")
F["mob"] << mob

mob
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
Read(var/savefile/F)
..()
loc = locate(F["x"], F["y"], F["z"])


When I open the game its only a black screen and The window Blockes completely...
In response to Vokicpower
Old savefiles are not going to be compatible. You could convert them if you really need to, but it's probably easier to just delete them and start from scratch.

Additionally, you'll need to load and save similarly to how it's done in client/New() and Del(). Note that if you are going to load after a player already has a mob, Logout() and Login() will be called, so saying the player logs in or out on them is going to be wrong. Such stuff should be moved to client/New() and client/Del().

Also, you still have gotos. Get rid of them. Again, a while() or for() loop can be used if you need a looping construct.
In response to Garthor
Thanks For The Help Man Now I understand what You Mean but I still need some explaination for While() and for() loop I dont Know how to use them I learned the stuff with GOTO and such in school 12 Grade so Could you try to explain ?
I have it so the Player when he logs in Client moves him to the location I want .I will delete the savefiles now .
But I still dont Know how to Save/ Load similary Like In Client/New() and such maybe you got another example for that ?

I understand now that New stands for a player who logs in and delete is for a player that Logs out (like in Logout/Usr.Del)
In response to Vokicpower
I suppose I shouldn't be surprised that they would teach you goto in high school...

goto is a terrible construct, which is pretty much left over from pure machine code (where its closest analogues are the ONLY flow control commands). Pretty much as soon as there was a language higher-level than Assembly, the more-readable alternatives while() and for() were created.

while(expr) will evaluate the expression in the parenthesis, and if it is true, will execute the block of code, then repeat (evaluate-execute-evaluate-execute...). It's what you generally go for when you just want something to repeat a somewhat-arbitrary number of times. So, for example:

// Ask for their favorite color until they say "blue"
var/answer = ""
while(answer != "blue")
answer = input("WHAT is your favorite color?") as text


for(init, cond, incr) will first execute init, then it will check cond, and if it's true will execute the code block, after which incr will be executed and cond will be checked again. So, it goes (init-cond-code-incr-cond-code-incr...). It's generally what is used when you want to execute something a more deterministic number of times. For example:

// Count to 10
for(var/i = 1, i <= 10, ++i)
world << i


Additionally, there are two keywords which help when you need more complex logic. break and continue. break will end the loop, and continue will begin the next iteration of the loop. So, for the case of (for example) choosing a name, you would wrap the whole thing in a while(1) or for(), both of which will continue infinitely. Then, you can evaluate whether a name is valid or not using multiple criteria, and if the name is invalid you can use "continue" to restart the loop, or "break" to end it.

As for saving and loading, the point is that calling Write() and Read() directly is not good, as it does not produce valid savefiles in every case. Instead, you need to use the << and >> savefile operators. So, F["mob"] << mob saves the mob and F["mob"] >> mob loads the mob. Note that, when loading, it doesn't matter what variable you are loading it into, as the key variable being loaded is what logs you in (changing the key of a mob causes any client with a matching key to take control). Additionally, loading a mob will create a NEW mob, not modify the current one, so remember to dispose of the current mob once the new one has been loaded.
In response to Garthor
Here is What I have so far, It saves the Location but as in the beginning I need to know how to save the Stats and such.
And Thank you Garthor for telling me this But unfortunately I dont know what to do . Is it my lack of english Or do I fail in Understanding people ? I dont know I need to get over with this code Its bugging me the whole Week I need to Proceed with coding other stuff I bet they will take a huge amount of time.



client
New()
if(fexists("Playersaves/[key].sav"))
var/savefile/F = new("Playersaves/[key].sav")
F[ "mob" ] >> mob
mob.loc = locate(9,9,4)
..()


Del()
var/savefile/F = new("Playersaves/[key].sav")
F[ "mob" ] << mob


mob
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
Read(var/savefile/F)
..()
loc = locate(F["x"], F["y"], F["z"])


mob
proc
Save()
var/savefile/F = new("Playersaves/[src.key].sav")
F[ "mob" ] << mob
F["x"] << x
F["y"] << y
F["z"] << z
Write(F)
src << "<font color=red><b>Your game has been saved!"
..()
mob/var/list
mob

turf
Load
icon='player.dmi'
icon_state="Load"
density=1
mouse_opacity=2
layer=10
Click()
usr.Load()


mob
proc
Load()
if(fexists("Playersaves/[src.key].sav"))
var/savefile/F = new("Playersaves/[src.key].sav")
F[ "mob" ] >> mob
F["x"] >> x
F["y"] >> y
F["z"] >> z
Read(F)




mob
verb
SaveVerb()
set name ="Save"
var/savefile/F = new("Playersaves/[usr.key].sav")
F[ "mob" ] << mob
F["x"] << x
F["y"] << y
F["z"] << z
Write(F)

mob/Login()
world << "<b><font face=tahoma><font size=-1><font color=white>[key] Logs in"
usr<<sound('closer.ogg',0)//Play this sound over and over again
usr.loc = locate(9,9,4)//When the mob logs in, take him to this point


It works so far, But when I click on load in the title screen I have Only the location, No icon I really dont know how to procceed AND I get this in my Dreamdeamon

World opened on network port 9999.
runtime error: Cannot execute null.Find().
proc name: New (/client/New)
source file: Mob.dm,297
BYOND hub reports port 9999 can be reached by players.
runtime error: Cannot execute null.Find().
proc name: New (/client/New)
source file: Mob.dm,297

Anyone Knows what to do ?
Page: 1 2