Blockland Forums > Help
Saving checkpoints
Blocki:
I was recently building a challenge and I noticed it would be cool if checkpoints save.
I tried it with VCE, where the checkpoint sets a variable to the number of the checkpoint.
But when the player leaves, the var is gone. How do I do this? (I fell like a noob now, I already done it a year ago but forgot how) It would also be cool if the variable stays when rehosting
zenloth:
I /think/ you could do it with player persistence.
--- Quote from: Badspot ---Add-On developers: You can use player persistence to save any tagged field on the client or player object by using the RegisterPersistenceVar() function. Here is some example code:
--- Code: ---//load the persistence add-on now, if they have it enabled.
//you can also use ForceRequiredAddOn if your add-on doesn't work without persistence
LoadRequiredAddOn("Script_Player_Persistence");
if(isFunction(RegisterPersistenceVar)) //quick way to check if the persistence add-on loaded
{
//usage: RegisterPersistenceVar(string <tagged field to match>, bool <match all>, string <datablock classname>);
RegisterPersistenceVar("myVariable", false, ""); // save %client.myVariable and %player.myVariable to persistence file (if those values are set)
RegisterPersistenceVar("myPrefix", true, ""); // save any tagged field on %client/%player starting with "myPrefix",
// eg %client.myPrefixFoo %client.myPrefix_24, etc.
// This is more expensive than a straight match and can have unintended consequences, so be careful
RegisterPersistenceVar("myDatablockRef", false, "ItemData"); // save %client/%player.myDatablockRef to persistence but verifies that it is of class "ItemData"
// and translates the id number into a datablock name before saving.
// Datablock id numbers will vary depending on the order and number of add-ons loaded,
// so use this if you need to save a datablock reference.
}
//optionally, you can package into the apply persistence function if you need to do custom stuff to fully restore the player's state
package <MyAddOn>PersistencePackage
{
function GameConnection::applyPersistence(%client, %gotPlayer, %gotCamera)
{
Parent::applyPersistence(%client, %gotPlayer, %gotCamera);
//Do custom stuff here...
}
};
activatePackage(<MyAddOn>PersistencePackage);
--- End code ---
Player Persistence files are saved as config/server/persistence/<blid>.txt
--- End quote ---
Alternatively there is a way to save vce variables, but I forget how it was done :c
Blocki:
Where do I get persitence
And will it work if I rehost
zenloth:
Persistence is a default add-on as of one of the releases...
It should work if you rehost as the variables are saved to a text file and then loaded on server/players connecting. I haven't had any experience playing with persistence and obviously some scripting knowledge is required, but yeh :3
Blocki:
How do I get persistence save the checkpoints