#I want to make get player data or dynamic properties but somehow it doesn't work

1 messages · Page 1 of 1 (latest)

unkempt light
#

I was trying to create get player data or dynamic properties form for admins so admins could see what's dynamic properties in the player but somehow it doesn't work

Here's the code:

getDataPlayer.show(source).then((response) => {
            if (response.canceled) {
                openAdminPanel()
                return;
            }

            const query = { type: "minecraft:player", name: allPlayers[response.formValues[0]] }
            const result = world.getDimension(response.formValues[1]).getEntities(query)

            const resultDataPlayer = new ActionFormHelper()
            resultDataPlayer.title(`Result Data Player "${allPlayers[response.formValues[0]]}":`);

            for (const player of result) {
                let rDP = player.getDynamicProperty(playerData)

                if (!rDP) {
                    resultDataPlayer.body(`Player named "${allPlayers[response.formValues[0]]}" do not have any data.`);
                    resultDataPlayer.button(`OK.`).do((eventData) => { getDataPlayerAdminPanel() });
                }

                resultDataPlayer.body(`
                Results from getting data from player named "${allPlayers[response.formValues[0]]}":\n \n----- Bank -----\nBank Name: ${rDP.bankName}\nMoney in the Bank: $${player.scoreboard.getScore(scoreboardworld.getObjective('moneyInBank')).formatCurrency()}`);
                
                resultDataPlayer.button(`OK.`).do((eventData) => { getDataPlayerAdminPanel() });
            }

            resultDataPlayer.show(source, { force: true });
        })

Oh yeah and I also use extra script "action-form-helper.js". The code: #973112187604312074 message

gritty valeBOT
#
Debug Result

There are errors in this [code](#1081244965545459862 message):

<repl>.js:1:1 - error TS2304: Cannot find name 'getDataPlayer'.

1 getDataPlayer.show(source).then((response) => {
  ~~~~~~~~~~~~~
<repl>.js:1:20 - error TS2304: Cannot find name 'source'.

1 getDataPlayer.show(source).then((response) => {
                     ~~~~~~
<repl>.js:3:17 - error TS2304: Cannot find name 'openAdminPanel'.

3                 openAdminPanel()
                  ~~~~~~~~~~~~~~
<repl>.js:7:61 - error TS2304: Cannot find name 'allPlayers'.

7             const query = { type: "minecraft:player", name: allPlayers[response.formValues[0]] }
                                                              ~~~~~~~~~~
<repl>.js:10:42 - error TS2304: Cannot find name 'ActionFormHelper'.

10             const resultDataPlayer = new ActionFormHelper()
                                            ~~~~~~~~~~~~~~~~
<repl>.js:11:59 - error TS2304: Cannot find name 'allPlayers'.

11             resultDataPlayer.title(`Result Data Player "${allPlayers[response.formValues[0]]}":`);
                                                             ~~~~~~~~~~
<repl>.js:14:53 - error TS2304: Cannot find name 'playerData'.

14                 let rDP = player.getDynamicProperty(playerData)
                                                       ~~~~~~~~~~
<repl>.js:17:60 - error TS2304: Cannot find name 'allPlayers'.

17                     resultDataPlayer.body(`Player named "${allPlayers[response.formValues[0]]}" do not have any data.`);
                                                              ~~~~~~~~~~
<repl>.js:18:72 - error TS2304: Cannot find name 'getDataPlayerAdminPanel'.

18                     resultDataPlayer.button(`OK.`).do((eventData) => { getDataPlayerAdminPanel() });
                                                                          ~~~~~~~~~~~~~~~~~~~~~~~
<repl>.js:22:64 - error TS2304: Cannot find name 'allPlayers'.

22                 Results from getting data from player named "${allPlayers[response.formValues[0]]}":\n \n----- Bank -----\nBank Name: ${rDP.bankName}\nMoney in the Bank: $${player.scoreboard.getScore(scoreboardworld.getObjective('moneyInBank')).formatCurrency()}`);
                                                                  ~~~~~~~~~~
<repl>.js:22:141 - error TS2339: Property 'bankName' does not exist on type 'string | number | boolean'.
  Property 'bankName' does not exist on type 'string'.

22                 Results from getting data from player named "${allPlayers[response.formValues[0]]}":\n \n----- Bank -----\nBank Name: ${rDP.bankName}\nMoney in the Bank: $${player.scoreboard.getScore(scoreboardworld.getObjective('moneyInBank')).formatCurrency()}`);
                                                                                                                                               ~~~~~~~~
<repl>.js:22:201 - error TS2552: Cannot find name 'scoreboardworld'. Did you mean 'Scoreboard'?

vestal thicket
#

anyway, try ```js
if (!rDP) {
resultDataPlayer.body(Player named "${allPlayers [response.formValues[0]]}" do not have any data.);
resultDataPlayer.button(OK.).do((eventData) => {
getDataPlayerAdminPanel() });
} else rDP = JSON.parse(rDP)

unkempt light
#

it doesnt work

vestal thicket
unkempt light
#

so i had to setup setDynamicProperty for these?

vestal thicket
#

what's
.do()even doin there

unkempt light
vestal thicket
#

unless u wana

unkempt light
#

i changed the new ActionFormHelper() to new ui.ActionFormData()
and i removed the functionality of the button

unkempt light
#

or should it be like this?

if (!rDP) {
                    resultDataPlayer.body(`Player named "${allPlayers[response.formValues[0]]}" do not have any data.`);
                    resultDataPlayer.button(`OK.`);
                } else rDP = JSON.parse(rDP)
                const { bankName } = rDP
vestal thicket
#

same thing

#

practice displaying every variable to know what data ur dealing with

vestal thicket
#

like ```js
console.warn(rDP)
//or
console.warn(JSON.stringify(rDP))

unkempt light
#

when i tried using try catch i realized

#

i forgot to add another option into the form 💀

frosty bough
#

You can also try jsfiddle in a web browser to write mockup code to test ideas, theories, and algorithms to save you some time.

frosty bough
# unkempt light wat do you mean

I had some code that I wrote yesterday that I needed to verify if it would work the way I intended it. The code required me to sort through an object that contained many different properties and to match those properties under certain conditions then execute based upon the conditions met. I did not feel like writing the code line for line and testing in a world multiple times as I wrote it out to debug. Instead I went to jsfiddle and wrote a mockup code that simulated the same logic as what I was aiming for with Minecraft and ran the code there to get results from console.log outputs. Once I got the code where I needed it I simply adapted it to my project. Knowing my code was good from jsfiddle I only had to really do one single test in a world just for sake of sanity and verifying that the code was still consistent in that environment.