Author Topic: Easy way of getting a brick's name on load?  (Read 1377 times)

At this point, I've wasted a lot of time just going through ways I could do it (First one would lead to crashes 80% of the time). It'd be great if someone could point to me a function that would work both when a brick is planted and one when it's loaded.

By name, you mean datablock name or is the brick named?

By name, you mean datablock name or is the brick named?
The name of the brick. I know how to get the name, but it usually doesn't work alongside functions that run on plant that I used. When I tried it with ::onAdd it would usually crash, even after a second delay.

what is the value of getting its name upon planting

Use echoes. Make it echo the name before the onAdd(); so you can know where the problem is.

Use echoes. Make it echo the name before the onAdd(); so you can know where the problem is.
uhh i'm not sure if that's possible here

Use echoes. Make it echo the name before the onAdd(); so you can know where the problem is.
There's nothing regarding it.
what is the value of getting its name upon planting
I'll need to double check since aparently i rewrote a lot of the code in a mostly-asleep haze, but I appeared to use this getSubStr(%obj.getName(),1,strlen(%obj.getName())) more recently, after bricks were loaded.

does anyone have the function calls the chat message "bricks have finished loading"? it seems i rewrote it to do its thing after all the bricks had loaded.

i mean like what are you actually doing because there may be a better way to do it

regardless, fxDTSBrickData::onPlant(%this, %obj) and fxDTSBrickData::onLoadPlant(%this, %obj) are the functions you probably want
« Last Edit: March 05, 2015, 06:14:55 PM by otto-san »

i mean like what are you actually doing because there may be a better way to do it
I'm using the brick names as a way of storing data regarding the brick. It's simple data; the name represents the "value"of the brick. It creates some more organized data later, the old structure would try and create the organized data instantly (It crashed when I tried it with onAdd, probably due to my own coding mistakes). The new structure I'm going for sends the brick to a list of data to be processed, and then when a function is ran, it processes it; hence why I'm looking for the function ran when all bricks are loaded/when a brick is completely loaded.

Code: [Select]
function fxDTSBrick::loadDataBasedOnName(%this) {
    %name = %this.getName();

    // your stuff
}

package brickNameThing {
    function fxDTSBrick::onLoadPlant(%this) {
        %this.schedule(1, loadDataBasedOnName);
        return parent::onLoadPlant(%this);
    }
};
activatePackage(brickNameThing);

Edit: You have to wait one tick before grabbing the name because it's not set during onLoadPlant.
« Last Edit: March 05, 2015, 08:36:35 PM by $trinick »

serverLoadSaveFile_End is called when a save is done loading FYI. I don't think that it has any args.

serverLoadSaveFile_End is called when a save is done loading FYI. I don't think that it has any args.

It'll be faster to do it as bricks are loaded rather than looping through all bricks are loading, especially if there are bricks present that weren't just loaded.