#How to add a delay? I was previously trying this but never got it working.

1 messages · Page 1 of 1 (latest)

dense cave
#

Here is the code. Someone told me system.run was what to use. Here is my script.

if (result.selection === 1) {
                modal6.show(player).then(result => {
                  if (result.cancelled) return;
                  var pname = getPlayerNames()[result.formValues[0]]
                  player.runCommandAsync(`execute as @p[name = ${pname}] at @s run fill ~~~ ~~~ powder_snow`);
                  player.runCommandAsync(`effect ${pname} slowness ${result.formValues[1]} 255 true`);
                  system.run(`execute as @p[name=${pname} at @s run fil ~~~ ~~~ air`) => {
                    result.formValues[1] * 20
                  };
outer arrowBOT
#
Debug Result

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

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

1 if (result.selection === 1) {
      ~~~~~~
<repl>.js:2:17 - error TS2304: Cannot find name 'modal6'.

2                 modal6.show(player).then(result => {
                  ~~~~~~
<repl>.js:2:29 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

2                 modal6.show(player).then(result => {
                              ~~~~~~

  @minecraft/server.d.ts:3428:15
    3428         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.
<repl>.js:4:31 - error TS2304: Cannot find name 'getPlayerNames'.

4                   var pname = getPlayerNames()[result.formValues[0]]
                                ~~~~~~~~~~~~~~
<repl>.js:5:19 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

5                   player.runCommandAsync(`execute as @p[name = ${pname}] at @s run fill ~~~ ~~~ powder_snow`);
                    ~~~~~~

  @minecraft/server.d.ts:3428:15
    3428         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.
<repl>.js:6:19 - error TS2552: Cannot find name 'player'. Did you mean 'Player'?

6                   player.runCommandAsync(`effect ${pname} slowness ${result.formValues[1]} 255 true`);
                    ~~~~~~

  @minecraft/server.d.ts:3428:15
    3428         class Player extends Entity {
                       ~~~~~~
    'Player' is declared here.
<repl>.js:7:30 - error TS2345: Argument of type 'string' is not assignable to parameter of type '() => void'.

7                   system.run(`execute as @p[name=${pname} at @s run fil ~~~ ~~~ air`) => {
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<repl>.js:7:87 - error TS1005: ';' expected.

7                   system.run(`execute as @p[name=${pname} at @s run fil ~~~ ~~~ air`) => {
                                                                                        ~~
<repl>.js:10:1 - error TS1005: '}' expected.

10 
   

  <repl>.js:2:52
    2                 modal6.show(player).then(result => {
                                                         ~
    The parser expected to find a '}' to match the '{' token here.

dense cave
#

I'm trying to get it to set the snowblock, then remove it after the set delay.

desert sky
#

import?

#

have you imported system

#

also any errors

dense cave
#

Import {system} from.....
No errors. Lol. It didn't work before I did that. I was just changing things. I may not have imported it correctly.

desert sky
#

at the last system.run

#

your command is …run fil…

#

i believe they also added a native fill function too

#

but it might be in preview

dense cave
#

Just fixed that. How do I import system.
import {world,system} from @mojang/server?

desert sky
#

if you don’t have any errors then the import should be correct

#

i don’t see any problems

#

actually

dense cave
#

OK. No errors. But the => has a red squiggly under it.

desert sky
#

import {world, system} from ‘@minecraft/server`

#

not mojang/server

#

also you need it in a string

dense cave
#

That's how I have it. I mistyped.

desert sky
#

what does it say

dense cave
#

I'm on mobile. It doesn't say anything

desert sky
#

wack

#

if there are no errors

#

then your commands probably are incorrect

#

runCommandAsync doesn’t tell you if there’s an error in the command the same way running the command does

dense cave
#

It will give me the slowness and set the snowblock. It does not full It with air after though.

dense cave
#

Even after fixing it.

desert sky
#

wait i just realized the => at the end

#

gtg sorru

dense cave
#

There is an error atthe squiggly line.

#

Does the command need to be a function?

restive dock
#

U can't get errors from .then()

#

U have to do

#

.then(//your code).catch(err => console.warn(err))

#

@dense cave

dense cave
#

so at the beginning it would be
.then(if result.selection......
};
)
.catch(err => console.warn(err))

restive dock
#

Try it

#

It will give u error

#

@dense cave

dense cave
#

I did not get an error. I also changed the code from above though. Doesn't work, but no errors show

restive dock
#

Um

#

You should remove that system run

#

And add world.say("test") there

#

For testing

#

If it works

#

@dense cave

frank herald
celest gyro
#

Damn just another long chat on a that simple problem

#

Now Im pissed off

#

Its a bad question he didnt even specify where to add delay, why, what function that is or what purpose, the whole chat is just filled with solving something that does not even relate to the question

#

And its late as hell

restive dock
#

If u don't know

#

Whats the problem

#

How would u solve

runic gate
#

here's spoiler```js
const targetName = res.formValues[0]
const tickTime = res.formValues[1]

const target = world.getAllPlayers().find(({name})=>name===targetName);
const {dimension,location:{x,y,z}}= target

const coords = ${x} ${y} ${z}

target.runCommandAsync(setblock ${coords} powder_snow 0)
target.runCommandAsync(effect @s add slowness ${tickTime} 255 true)

const sId = system.runSchedule(()=>{
system.clearRunSchedule(sId)
dimension.runCommandAsync(setblock ${coords} air 0 replace powder_snow)
},tickTime*20)

dense cave
#

@runic gate
Thanks for the help.
I'll close this or admin can close this. I didn't mean to make anybody upset for a asking a question. Lesson learned.
I probably won't try to get help on here anymore.
At least you were able to read the question, look at the code and see what I was saying.

#

@celest gyro
All I wanted to know was how to add a delay between commands.
I believe my question was "How to add a delay?". Since It is "scripts" I figured it was obvious it was for scripts. Why does it matter for what? Why does it matter where the delay is? I sent the script I had and said what I was trying to do in the very next message. You got all "pissed off" because you didn't read it and just couldn't keep your tiny little fingers from letting everyone know you are upset. . How's the saying go? If you don't have anything nice to say, keep your damn mouth shut.

I'm sorry but people acting that way really makes all the good people on here look bad. Makes me real hesitant to ask for help if someone like that is just gonna butt in with nothing helpful. People like that can easily just move on to the next question. It makes a place that should be safe for questions, seem like the opposite. Sorry that stupid comment made me mad. If you don't want to help fine. But keep your mouth shut if it's only to disparage someone.

celest gyro
# dense cave <@461513673719021568> All I wanted to know was how to add a delay between comma...

Bro chill, no need to be outragious, it was late and when it is late I tend to do stupid stuff and not behave all that great, Im sorry, tho this is a little too much.

You wanted to add delay but from your question and code it wasnt very clear, the first few things in here I saw were literally just fixing errors overall in an long conversation and when theres more info on where to add the delay more it can be frustrating having to look through all chat just to find it.

No I wanted to help I just pointed out how you can make it a lot easier for other people that want to help you. I have done everything that you may need with delay already so I would've helped if the above was given

dense cave
#

I understand being irritated. My name starts with Angry. I could've been more sympathetic as well. It is just, I felt I did a decent job explaining what I was trying to do. I wanted to spawn a snow block, add slowness to Player so they don't move then wait for a delay and fill (the snow block) with air to remove it.
I'm making an admin fun/troll gui. I couldn't think of another way to freeze a player.

#

The script does set the block, it does add the slowness. I'm gonna try what m9 sent.

#

Sorry if I upset you. Its early. Have a good day.

celest gyro
#

Have a great day too

dense cave
#

I appreciate the help. @runic gate
I had to edit what you gave a little bit but I got it working.

  if (result.selection === 1) {
                modal6.show(player).then(result => {
                  if (result.cancelled) return;
                  let selected = result.formValues[0]
                  let tickTime = result.formValues[1]
                  let target = players[selected]
                  let targetName = playerNames[selected]
                  console.log([target.name, targetName])
                  target.runCommandAsync(`setblock ~ ~ ~ powder_snow 0`);
                  target.runCommandAsync(`effect @s slowness ${result.formValues[1]} 255 true`);
                  const sId = system.runSchedule(() => {
                    system.clearRunSchedule(sId)
                    target.runCommandAsync(`fill ~ ~ ~ ~ ~ ~ air 0 replace powder_snow`)
                  }, tickTime * 20)
                })
              }