ID:159449
 
My answer is simple, lets say I had a verb that allows you to edit an offline mobs variables, by inputting their key and checking to see if they have a savefile, if they do how could I make it to where var/d = input("Insert Key") as text and then make it so d.gold += 100, so to speak.

If you did not understand that(I am horrible at explaining things) try this makeshift code I just coded that I know will not work because it would say d.goldcoins is undefined.

mob/Owner
verb
Send_Gold_Coins()
set category = "GM"
if(usr.key != "SadoSoldier")
alert("Sending players coins, without my permission, WILL result in a ban no matter who you are!")
var/d = input("Please input their key:") as text
if(fexists("players/[d]"))
var/c = input("How many Gold Coins?") as num
d.goldcoins += c
else
usr<<"<b>There is noone by that key!"
return
<dm>
That is just an example, so how would I go about this?
Or you can just do...
<dm>
var/list/Players
for(var/client/C)
Players += C.mob
var/p = input("Whowould you like to give coins to?","Give Coins") as null|anything in Players
if(!p) return
//...
In response to Spunky_Girl (#1)
...I should've thought of that -__- Thanks
In response to Spunky_Girl (#1)
Just to see if I did it wrong, would I have it p.goldcoins += c because if so, the code doesn't work(once I can get it to work I'm going to recode it)
Obviously, you'd have to open the savefile, then look for the place the value you want to change is stored, then overwrite that value with the << savefile operator. The exact method of doing this can vary depending on how you're saving your mobs.
In response to Spunky_Girl (#1)
Considering he wants to edit offline players' mobs and not currently logged in players', that post is (excuse me, miss) utterly useless since there is no mob (or even a client) present to edit. Rather, the only course of action would be to edit the mob's savefile, or queue up and keep track of 'offline changes' made to it then apply them when the player logs in.
In response to Kaioken (#5)
Oh, I must've overlooked that then. Sorry.
In response to Spunky_Girl (#6)
Didn't matter I can't figure it out no matter what I do, I've tried so many things and the last thing I tried should have worked. I make a global var:

var
list
Players1 = list()


Then I added the usr to the list on Login():

mob
Login()
Players1 += usr//I tried Players1.Add(usr) as well, I also tried using src
..()


Then I tried searching for it in the verb and use it:

mob/Owner
verb
Send_Gold_Coins(var/mob/M in Players1)
set category = "GM"
if(usr.key != "SadoSoldier")
alert("Sending players coins who have not paid, without my permission, WILL result in a ban no matter who you are!")
var/c = input("How many Gold Coins?") as num
M.goldcoins += c


But alas, nothing worked. When I looked at the DM Guide it didn't make to much sense to me since I'm horrible at codes that leave .dm and image files. So I don't know what to do... The code above does nothing when I click the verb.
In response to SadoSoldier (#7)
mob/Owner
verb
Send_Gold_Coins()
set category = "GM"
var/mob/p = input("Please type their key:") as text
var/c = input("How many Gold Coins?") as num
if(usr.key != "SadoSoldier")
alert("Sending players coins who have not paid, without my permission, WILL result in a ban no matter who you are!")
for(var/mob/M in world)
if(M.client)
if(M.key == p)
M.goldcoins += c
return
else
return
if(fexists("players/[p]"))
if(usr.key != "SadoSoldier")
alert("Sending players coins who have not paid, without my permission, WILL result in a ban no matter who you are!")
var/savefile/F = new(p)
var/mob/L
Read(p)
L >> F
L.goldcoins += c
Write(p)
L.Logout()

Schnitzel gave me a list of what I had to do and gave me the link to the BYOND Guide that has to do with savefiles but as soon as I got this far he logged off and it still doesn't work even if the key is online or offline, it doesn't matter. Oops time to eat I will be back in around 20-30 mins.
In response to SadoSoldier (#8)
I'm not quite sure, but I think those "return"s are not only stopping the loop, but also halting the snippet altogether. Try using "continue" instead? :\
In response to Spunky_Girl (#9)
I want it to stop the code after it hits that point though, I'm making this code able to use for people who are online and offline..
In response to SadoSoldier (#10)
I doubt you want the function to stop immediately after finding a mob without a client, as that will prevent it from continuing to do anything useful. The first mob may well probably be clientless all of the time, so that kills your function as it stops without completing all its for() iterations or finding a player with the key. Your 'else break' would have been 'else continue' to make it work, but nothing is even needed to put there in the first place. You should also just loop through clients anyway and not all mobs (including your tenths or hundreds of NPCs, of course) then check if they happen to have a client.
Also, you're not using Read() correctly at all. Note its an object proc, not a global one, therefore you're calling it on src to load the data from the savefile into it instead. The argument also needs to be a savefile reference.
The usage of << is also wrong (the savefile is always on the left-hand side with savefile operators, not the var to read/write to) and also potentially unneeded. You only need either to call either Read() or <<, not both. You need to use the one corresponding to the method you're using to save the mobs into the savefiles.