#DynamicProperty

1 messages · Page 1 of 1 (latest)

fringe badge
#

Hi guys. I have a Dp, part of its value is changed when the if explanation is fulfilled. After part of its value changes, I print this Dp and it was printed correctly, that is, after updating, but when I print it after that in another function, the old Dp is printed. Does anyone have a solution? ?

fringe badge
#

DynamicProperty

hexed osprey
#

Is this for an itemStack that is in a container or an entity's inventory? If so you should be using the get/set dynamic property methods on the container slot instead of getting the item. Otherwise you need to manually replace the item in the container.

fringe badge
formal cloud
#

Perhaps showing code might help.

fringe badge
fringe badge
# formal cloud Perhaps showing code might help.
        const nowClanDp = world.getDynamicProperty("nowClan")
              let clanrole;
              const inClan = world.getDynamicProperty(playerName + "_inClan");
              if (inClan) {
                clanrole = nowClanDp.split("/")[1];
              }
              const NewClanRoleDp = nowClanDp?.replace(clanrole, "Minato");
              world.setDynamicProperty("nowClan", NewClanRoleDp);

When I print the dynamic property "nowClan" right after the code, it is printed after the replacement, but when I print it in another function, it is printed before the replacement.

formal cloud
#

Sorry, I'm confused in what you're actually trying to do.

fringe badge
formal cloud
formal cloud
#

So your problem is when you call it, it works fine as you expect. And then when you call it again from another function it works differently?

formal cloud
#

When you call the function the first time, it works as intended. But the second you call it, it will run the code again redoing all stuff again. So this might be the reason why it won't work as you intend to do.

Maybe provide more info on what you're actually trying to do.

fringe badge
formal cloud
#

Perhaps the problem is not within that function only.

fringe badge
formal cloud
#

I mean the problem could also be from another code affecting it.

fringe badge
formal cloud
#

Couldn't tell the problem if we can't even see it. We can't debug something we don't even know what to debug.

The snippet isn't enough to tell the actual problem.

fringe badge
fringe badge
# fringe badge I cannot send you the original code because it is long and contains other unrela...

@formal cloud

function FirstFunction(player) {

//Create the Dp in the first function
//
//

const MyDp = "MyDp";

const Array = ["One", "Tow", "Three"]

world.setDynamicProperty(player.name + "_PlayerDp", MyDp)

world.setDynamicProperty(MyDp, player.name + "/" + Array + "/");

}

function SecondFunction(player) {

//Change the Dp value in the second function
//

const Playerdp = world.getDynamicProperty(player.name + "_PlayerDp");

const Worlddp = world.getDynamicProperty(Playerdp);

const lastName = Worlddp.split("/")[0];

const newdp = Worlddp.replace(lastName, "Test");

world.setDynamicProperty(Playerdp, newdp);

}

function ThirdFunction(player) {

//Call the Dp after the change
//

const pDp = world.getDynamicProperty(player.name + "_PlayerDp")

player.sendMessage(world.getDynamicProperty(pdp).split("/")[0]); //It is supposed to print "Test", but it prints the name of the player (player.name), that is, before the change

};
formal cloud
#

I call it in this order

firstFunction(player);
secondFunction(player);
thirdFunction(player);
#

I analyze how your code, sems nothing wrong, but your DP system is very confusing and hard to understand, idk where and how do you use it. Maybe try to store your DP into JSON string, this allows you to easily manage DP and easier to understand too.

This is how I analyze your code

/* Assume "Steve" is the player name
 * The comments show how the string will look like for each line
*/
function FirstFunction(player) {
    //Create the Dp in the first function
    const MyDp = "MyDp";
    const Array = ["One", "Two", "Three"]
    world.setDynamicProperty(player.name + "_PlayerDp", MyDp) // id: "Steve_PlayerDp", value: "MyDp"
    world.setDynamicProperty(MyDp, player.name + "/" + Array + "/"); // id: "myDP" value: "Steve/One,Two,Three value"
}

function SecondFunction(player) {
    //Change the Dp value in the second function
    const Playerdp = world.getDynamicProperty(player.name + "_PlayerDp"); // return "myDp"
    const Worlddp = world.getDynamicProperty(Playerdp); // return "Steve/One,Two,Three/"
    const lastName = Worlddp.split("/")[0]; // return "Steve"
    const newdp = Worlddp.replace(lastName, "Test"); // return "Test"
    world.setDynamicProperty(Playerdp, newdp); // id: "MyDp", value: "Test"

}

function ThirdFunction(player) {
    //Call the Dp after the change
    const pDp = world.getDynamicProperty(player.name + "_PlayerDp"); // return "MyDp"
    //It is supposed to print "Test", but it prints the name of the player (player.name), that is, before the change
    player.sendMessage(world.getDynamicProperty(pDp).split("/")[0]); // "Test/One,Two,Three/" -> ["Test", "One,Two,Three", ""] -> index 0 is "Test"
};
fringe badge