ID:2808623
 
So, I've tried to do this for a while but it doesn't even read it properly, so I have a saving and loading of ranks via save file but it doesn't work right when I try to read the rank to see if someone is possessing it or not.

I've tried if(!Leader) to read it, but it hasn't been working. Is there another way to do it? I have standard saving and loading systems. The files are saved occasionally in-game, and loaded whenever the world boots up. (I only put the relevant pieces of code as a demonstration btw)

//code attempt to check it
if(!Leader)
Leader=M.key

//saving code
var/savefile/S=new("RANK")
S["Leader"]<<Leader

//loading code
if(fexists("RANK"))
var/savefile/S=new("RANK")
S["Leader"]>>Leader
//Saving
var/savefile/S = new/savefile("Saves/[ckey]")
S["Leader"] << Leader

//Loading
if(fexists("Saves/[ckey]")
src << "Save found!"
var/savefile/S = new/savefile("Saves/[ckey]")
S["Leader"] >> Leader
else
src << "No save found."

Running out the door so I didn't double check my syntax, but you can try this.
I should be more specific, the Leader checking is separate, those 2 saving and loading codes are just for the RANK save file. I'm trying to make a third separate code I can use wherever to check if the rank is taken. "Leader" is one of many rank variables saved to the RANK save file
Or another use for it could be like, checking if an object's been taken from an area so it doesn't reappear like a sword or something after a reboot. Basically a player or object related save file, how would I check that when the world runs?
Essentially I want to make it so I can read a savefile for the Leader ranking, and then affect the game with that.
I'm not 100% clear on what you're asking. But I think the solution you're looking for is some type of LevelManager.

You want a way to save a var that can be accessed by everyone to check if the rank is available or not?

If so, you can just create a singleton in the world on new and load/save vars to it. Then all of your mobs can check it.
levelManager
var
whoIsLeader = null

var
levelManager/levelManagerSingleton

world
New()
..()
levelManagerSingleton = new()

Then you can just save/load whatever vars you want to your levelManagerSingleton. In this case I setup whoIsLeader.

Then when your mob wants to check if the rank is taken...
mob
proc
CheckLeaderTaken()
if(levelManagerSingleton.whoIsLeader != null)
src << "Rank is taken by [levelManagerSingleton.whoIsLeader]"

Hope I understood your question and that this helps you. Keep on GRINDING!
In response to Grind Knight
Basically I'm trying to make a save file reader, cuz I have ranks saved and loaded by the game automatically, I'm trying to make it so the game can read the save file and check for specific variables from it
In response to Narutogx2
Then go back and read my first post. Just load the location of the save file and then write the vars from it to vars in the game. Then read them.
In response to Grind Knight
To me that code just looks like ur just remaking the save and load mechanics, lol. What I'm trying to do is pull it from an existing save file, which is the RANK save file, if that's possible. The problem is I'm trying to figure out how I read them, because the code I mentioned to try to isn't working.
In response to Narutogx2
It's opening a temporary savefile to read from. You want to read a save file and have your game check the variables from it, right?

So:
var/globalRankVar

proc
//Loading
if(fexists("Saves/Global/World.sav")//Change the path to whatever save file you're using.
src << "Save found!"
var/savefile/S = new/savefile("Saves/Global/World.sav")
S["Leader"] >> globalRankVar
else
src << "No save found."

You create your temporary savefile. Then you copy its data into your world var(s). Then you're done and can access them.
In response to Grind Knight
The thing is, its not a temporary save file, its a permanent save file that's always accessible to anyone, because it also references a list with the variables.

I have a way to list them so people can see who is what rank, but not a way for the game to check that same list to see if the rank is taken. That's what I'm trying to figure out. I was trying to do it with a simple If statement, and I can't get it to work for some reason.

This part is the relevant part to what I'm trying to do in a sense of making someone the rank, it would check the savefile if there is a leader, and then if there isn't it would make them the leader.
//code attempt to check it
if(!Leader)
Leader=M.key

//this part is the variable itself which gets taken up by the loaded savefile rank (there's multiples of these)

var/Leader = ""
In response to Narutogx2
You're not understanding what I'm trying to tell you.

1. Your world starts.
2. Load your save file.
3. Take the vars from your save file and save them to global vars in your world.
4. Your users can check/access that global var.
5. When your world goes down you save those global vars to your save file.

Done.
In response to Grind Knight
The problem is when number 4 comes in, I can't check them. It doesn't work, that's the whole reason I made this page, lol. For instance, when do like (these are placeholders btw)
if(ObjectTaken)
for(var/obj/Object/A in world)
var/mob/M
if(!A in M.contents)
del(M)
else return

It doesn't work and completely ignores it. This version is to prevent an object from respawning on a reboot if its been taken, but it completely ignores it because its not checking if the rank is taken or not. The variables are loaded when the world starts up, but its still breaking.
In response to Narutogx2
When you load the save file you need to save it to a global var, not a mob var.
In response to Grind Knight
Its not a mob var, its just var/Leader = "", the loading overwrites it. The loading and saving I have no troubles with, its READING those files, lol. ObjectTaken is the variable I'm trying to read off of the save file that literally just isn't registering. I should mention, this is not a player save file. Its just a game save file.
Ok I figured it out, I had to change if(ObjectTaken) to if(global.ObjectTaken) and then I had to make it a world proc that starts when the world does. I didn't have to change anything with my saving or loading mechanics.

I assume the same will work for checking ranks when trying to make people them, if someone already has it.

Pre-Post Update: For some reason I didn't need the global for a player rank, maybe because its player given, but before it wasn't working and idk why. It's weird I guess.

Post-Post Update: Its cuz I didn't add an else return onto it lol.

So basically I had to just change it to this
if(global.ObjectTaken)
for(var/obj/Object/A in world)
if(A.loc == locate(XYZ))
del(M)
else return