#help with system.runTimeout

1 messages · Page 1 of 1 (latest)

real meadow
#

Hi, I was coding a script file and I used two runTimeout function, but the second doesn't work.
Basically it works one time, and doesn't work anymore. Do somebody knows why it's happening?

#
system.runTimeout(() => {
    for (let player of world.getPlayers()){
        let inventory = player.getComponent("minecraft:inventory");
        for (let i = 0; i < 36; i++){
            let item = inventory?.container.getItem(i);
            let test = item?.typeId
            switch (test){
                case undefined:
                    continue;
                    break;
                case "se:philosopher_stone":
                    player.runCommandAsync("function potion_query_3_1")
                    break;
            }
        }
    }
}, 1800)```
#

Pd: It works, all code run, but it doesn't work well

dusky yew
#

say what is happening and say what you expect

real meadow
#

Ok,

#

It should run more than one time, for example, my idea is that it gives me items for each 90 seconds, but it gives me the item one time, how I said. I try putting 1800 ticks of delay but nothing happens, and I try with 20 ticks of delay and nothing

#

I would want that, while I have the item into inventory, it gives me items for each 90 seconds

#

But just gives me one time

solar beacon
#

runInterval not runTimeout

#

I gonna assume that you are only calling the function one time

#

Timeout just run one time, interval runs more than one time

real meadow
#

Ummmm okay

#

I guessed runTimeout runs more than one more but using delay

solar beacon
#

No it is like an sleep or delay function

real meadow
#

Well, finally I could make it. I used the runInterval function that I had

#

I made a system using scoreboards

#

Thank you very much

rich mist
#

it's the loop thats multiplying the /function

real meadow
rich mist
#

like
for every philosopher_stone u have in ur slot, it triggers that much

real meadow
#

Ummmmmmmm okay

#

I get it

#

Well, important thing is that I solved it 😅

#
system.runInterval(() => {
    for (let player of world.getPlayers()){
        let inventory = player.getComponent("minecraft:inventory");
        for (let i = 0; i < 36; i++){
            let item = inventory?.container.getItem(i);
            let test = item?.typeId
            switch (test){
                case undefined:
                    continue;
                    break;
                case "se:artifact":
                    player.runCommandAsync("scoreboard objectives add Kills dummy");
                    player.runCommandAsync("scoreboard players add @s Kills 0");
                    player.runCommandAsync(`titleraw @s actionbar {"rawtext":[{"text":"§bTienes §e"},{"score":{"name":"@s","objective":"Kills"}},{"text":"/10 §bkills§r"}]}`);
                    break;
                case "se:artifact_ii":
                    player.runCommandAsync("scoreboard objectives add Kills dummy");
                    player.runCommandAsync("scoreboard players add @s Kills 0");
                    player.runCommandAsync(`titleraw @s actionbar {"rawtext":[{"text":"§bTienes §e"},{"score":{"name":"@s","objective":"Kills"}},{"text":"/10 §bkills§r"}]}`);
                    break;
                case "se:philosopher_stone":
                    player.runCommandAsync("scoreboard objectives add pot dummy");
                    player.runCommandAsync("scoreboard players add @s pot 1");
                    player.runCommandAsync("scoreboard players set Potion pot 1800");
                    player.runCommandAsync("execute if score @s pot = Potion pot run function potion_query_3_1")
            }
        }
    }
})```
#

I did it

rich mist
#

why not use the scoreboard api

real meadow
#

Because I feel more comfortable using /scoreboard for the functions

#

But thanks for the fact

#

By the way, @rich mist , is there a way to test if the player has equipment an item and if him has x health value?

#

Because the animation that I made just works one time

rich mist
#

yeah...

real meadow
rich mist
#

player.getComponent('health').currentValue

#

yeah

real meadow
#

Ummm okay

#

But how I get the value?

#

Ahhhhhhhh okay

#

Thank you very much

#

It returns a number, right?

real meadow
#

I don't have that version

#

I have 1.20.10 and I use 1.4.0-beta

#

Does it matter?

rich mist
#

hmm

#

its prob .current

real meadow
#

Okay, I'll try

#

Thanks ^w^

real meadow
real meadow
#

I already learned, thanks