#Form | Pass dropdown value to another form
1 messages · Page 1 of 1 (latest)
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?
//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
instead of having const = inside the playerTPA have it outside as a let an set it inside the playerTPA function
that allows you to use the variable globally
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'
You can use .catch() method after .then() method for getting errors
doesnt return any errors🥹
im just gonna re write it all and see😭
ive been working on it for 5 hours
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
@deep plover
Yea?
like that
Oh mb I didn’t see that
What’s source?