#Form | Pass dropdown value to another form

1 messages · Page 1 of 1 (latest)

deep plover
#

I have a modal form with a dropdown in it and it defines the response to that dropdown as a const. I'm not sure how to get that dropdown response into another function and I dont think you can put a function inside of another function.

#

so lets say my dropdown is defined as

const response = ...

in one funtion

#

is there a way i can get that same property in another function?

deep plover
#
//TPA Menu
function tpaMenu(player) {
  let tpaMenu = new ActionFormData
  tpaMenu.title('Tpa Menu')
  tpaMenu.body('Use this menu to send/accept tpa requests.')
  tpaMenu.button('Send A TPA Request')
  tpaMenu.button('Accept TPA Request')
  tpaMenu.show(player).then(result => {
    if (result.selection == 0) {return playerTPA(player)}
    if (result.selection == 1) {return acceptTPA(player)}
  })

}
//END

//Send TPA Request
function playerTPA(player) {
  let playerTpa = new ModalFormData()
    const players = [...world.getPlayers()];
    playerTpa.title('Teleport Request')
    playerTpa.dropdown('Select A Plyer To Send A Request To', players.map(plr => plr.name))
    playerTpa.show(player).then(({formValues: [dropdown]}) => {
      const tpaTag = (player.getTags().find(tag => tag.startsWith('tpaTo:')))
      const selectedPlayer = players[dropdown];
      if (selectedPlayer.hasTag(`hasTpaReq`)) {
        player.tell(`§7[§cTPA Error§7]: §e${selectedPlayer.nameTag}§7 has a pending request.`)
        player.playSound('random.glass') 
        return;
      }
#
      if (selectedPlayer == player) {
        player.tell('§7[§cTPA Error§7]: You cannot select yourself.') 
        player.playSound('random.glass') 
        return;
      }
      if (!selectedPlayer.hasTag(`hasTpaReq`)) {
          selectedPlayer.playSound('random.orb')
          selectedPlayer.addTag('hasTpaReq')
          selectedPlayer.tell(`§7[§6TPA§7]: §e${player.name}§7 has sent you a tpa request.`)
          selectedPlayer.tell(`§7If you do not accept, the request will automatically decline after 60 seconds.\nYou can accept your request in the player teleport tab in your realm navigation.`)
          selectedPlayer.runCommandAsync(`scoreboard players set @s tpaClock 60`)
          player.addTag(`tpaTo:${selectedPlayer.nameTag}`)
          player.tell(`§7[§6TPA§7]: Request sent to §e${player.name}§7.`)
      }    
      system.runSchedule(() => {
        for (const self of world.getPlayers()) {
      if (self.hasTag(`${tpaTag}`) && getScore(selectedPlayer, 'tpaClock') == 1) {
        selectedPlayer.tell(`§7[§cTPA§7]: Request timed out.`)
        selectedPlayer.removeTag('hasTpaReq')
        self.tell(`§7[§cTPA Error§7]: Request timed out.`)
        self.removeTag(`${tpaTag}`)
        self.playSound('random.glass')
            }
          }
        },18 
      )
    }
  )
}
function acceptTPA(player) {
let acceptReq = new ActionFormData
acceptReq.title('Accept Tpa Request')
acceptReq.body('Are you sure you want to accept this tpa request?')
acceptReq.button(`§aAccept Request`)
acceptReq.button(`§cDecline Request`)
acceptReq.show(player).then(result => {})
}```
#

i want to get the const's from the playerTPA function into acceptTPA function at the bottom

#

if that helps

amber plank
#

that allows you to use the variable globally

deep plover
#

wouldnt work in my case cause the dropdown is defined in the function(i think)

#
playerTpa.show(player).then(({formValues: [dropdown]}) => 
#
const selectedPlayer = players[dropdown];

this is what im specifically trying to 'export'

proud void
#

You can use .catch() method after .then() method for getting errors

deep plover
#

doesnt return any errors🥹

#

im just gonna re write it all and see😭

#

ive been working on it for 5 hours

ebon pebble
#

call accept tpa from tpa requet fumction

#

Form | Pass dropdown value to another form

deep plover
#

Not sure how

#

Or what that means

ebon pebble
#
requestTPA(player)
  result = show form to player
  get target from result
  acceptTPA( target, player )

acceptTPA( player, source )
  result = show form to player
  if yes 
    tp source to player
ebon pebble
#

@deep plover

deep plover
#

Yea?

ebon pebble
#

like that

deep plover
#

Oh mb I didn’t see that

ebon pebble
#

the player where targeted player will be tped to

#

player a, b

a request b for tpa
accept form shows to b
if he yes then a tped to b

#

a is source