Author Topic: [Solved] Brick Variable Persistence  (Read 1892 times)

Hey guys, so recently I've been operating on the assumption that brick variables save when you do Save Bricks, and load when you do Load Bricks. I made a land ownership system, and theres a variable that gets saved when you own that brick. For example, it'd be %brick.owner. But, when I save the bricks and load them again, all records of land ownership are gone. Is there any way to combat this?

Edit: There are two possible people that can own a peice of land. Either a tribe, or a player. %brick.owner can be either or. I can't use the trust system for a multitude of reasons. First, I'm using a custom build system that allows people to only build with backpack resources. You press R, it fires a raycast, and plants where it ended up. Second, you can't attribute trust to tribes.
« Last Edit: August 12, 2015, 11:01:53 PM by Johnny Blockhead »

You should look into creating custom brickgroups. A few forum searches should do it.

could give it an onbrickloaded event which would save and be loaded

You can create a fake event for saving the data.

Okay, thanks guys for giving me some pointers. In the RPG I'm creating, there's a limited amount of resourced available on the (very large) map. What I'd want to do is load up a save file of all of the resources around once a day, so that the supply keeps replenishing. I made it so that all of the resource bricks are put in their own brickgroup, so is there a way to just load a single brickgroup in a save file? I know that serverDirectSaveFileLoad exists.

package CharmLoading
{
   function fxDtsBrickObject::onLoadPlant(%brick)
   {
      parent::onLoadPlant(%brick);
      if(%brick.getDatablock().category $= "SurvivalRPG")
      {
         Brickgroup_Resources.add(%brick);
      }
   }
};
activatePackage(CharmLoading);


My previous question still stands. I did a few searches, I learned about Brickgroups but I'm still not sure how it'd help me. I don't really know what a fake event would do, so I'm left pretty clueless.

Edit: Can I package that loading function to ignore loading everything but my brickgroup? How'd that work?
Edit 2: I created a brick, and packaged onPlant for it so it creates a trigger around it. Would that trigger stay if I save it, and load it? Or do I also have to copy/paste and package onLoadPlant
« Last Edit: August 12, 2015, 01:54:16 PM by Johnny Blockhead »

For loading bricks into a different brickgroup just change $LoadingBricks_BrickGroup.

Edit 2: I created a brick, and packaged onPlant for it so it creates a trigger around it. Would that trigger stay if I save it, and load it? Or do I also have to copy/paste and package onLoadPlant
Either do the same thing in onLoadPlant or call onPlant in onLoadPlant.

No, what I want to do is make it so only bricks with a certain brickgroup are loaded.
Code: (doesn't work)
function refreshResources()
{
   $LoadingBricks_Brickgroup = "Resources";
   serverDirectSaveFileLoad("saves/Survival.bls", 3, "", 2);
}

The trigger thing worked. What are you guys talking about with the events?
Edit: If I can't load brickgroups individually, I can just place the resources everywhere and then loop through the other brickgroups and delete the bricks. Then load that save.
« Last Edit: August 12, 2015, 03:27:46 PM by Johnny Blockhead »

No, what I want to do is make it so only bricks with a certain brickgroup are loaded.
Code: (doesn't work)
function refreshResources()
{
   $LoadingBricks_Brickgroup = "Resources";
   serverDirectSaveFileLoad("saves/Survival.bls", 3, "", 2);
}

Edit: If I can't load brickgroups individually, I can just place the resources everywhere and then loop through the other brickgroups and delete the bricks. Then load that save.
Brickgroups aren't saved into bls files.
You could have a save of just the resources and then load that into it's own brickgroup.
What are you guys talking about with the events?
You said you wanted to save custom variables onto bricks. Make your own fake event. Add it onto the brick. Retrieve the data from the event when the brick is loaded.

Something like this:
Code: [Select]
registerOutputEvent("fxDTSBrick", "myFakeOutput", "string 200 19");

%brick.addEvent(%enabled, %delay, %inputEvent, "Self", "myFakeOutput, "myVariable 49493");
Then package onLoadPlant to get the data from the event and give the brick that variable.

I did that, and I found out that the value is stored by %brick.eventOutputParameter0_1 when it's the only event. It's a tagged string though, and when I do talk("Save Variable:" SPC %brick.eventOutputParameter0_1);, it just does save variable: since it can't talk that variable. I also tried doing %var = getTaggedString(%brick.eventOutputParameter0_1); talk("Save Variable:" SPC %var);, but it didn't work. How do I get the tagged string to work?

Edit: Wait, nevermind. %brick.eventOutputParameter0_1 is empty. I did a dump() on the brick, and it does say that eventOutputParameter0_1 is "varhere value". Weird.
« Last Edit: August 12, 2015, 04:27:07 PM by Johnny Blockhead »

It's not a tagged string - the parameters are zero-indexed as well as the events themselves.

Oh, I must have thought that because it was under the Tagged Fields section.
What am I supposed to do so I can get the value of %brick.eventOutputParameter0_1?

It's not a tagged string - the parameters are zero-indexed as well as the events themselves.
No, the parameters are 1-indexed. It makes no sense, but they are.


Okay so, this is what happens when you dump the brick.
I tried using %brick.eventOutputParameter0_1 , but when you talk it, it doesn't do anything. When I try and compare it to a spring thats identical to its value, the if-check fails. My goal is to manipulate it with getWord.

You clearly didn't access the variable correctly. %brick was most likely not defined if you used the console. Try it with the actual object id or use a global variable for testing with console!

It worked with the Object ID. I think it might be that I'm parenting onLoadPlant. and the events might not have loaded yet? I'll try putting the check on a schedule and seeing what happens.
Edit: That worked.
« Last Edit: August 12, 2015, 10:54:12 PM by Johnny Blockhead »