Carpet

Carpet

2M Downloads

Script not working after login back.

leucome opened this issue ยท 5 comments

commented

So I tried to make a prospector torch based on the prospector pick. And noticed that if I log out and back in the script don't work anymore. I need to load the script manually or restart the server. The original pick script also behave like that. I am not sure if it is a bug or if we need to add something else to resume the thing once we come back. I made a script that run a reload command on player_connect to fix this. But this solution feel kinda overkill. There is probably an other way.

The server I use is fabric for 1.17.1

There the example of the script in question.

`// scarpet 1.4

// stay loaded
__config() -> (
m(
l('stay_loaded','true')
)
);

global_mineral_ores = l(
l('coal_ore','dust 0.1 0.1 0.1 0.5'),
l('redstone_ore', 'dust 0.9 0.1 0.1 0.5'),
l('lapis_ore', 'dust 0.1 0.1 1.0 0.5')
);
global_metal_ores = l(
l('iron_ore', 'dust 0.6 0.3 0.1 0.5'),
l('gold_ore','dust 0.9 0.9 0.0 0.5'),
l('nether_gold_ore','dust 0.9 0.9 0.0 0.5'),
l('ancient_debris', 'dust 0.2 0.2 0.2 0.5'),
l('copper_ore', 'dust 0.7 0.5 0.0 0.5')
);

global_crystal_ores = l(
l('nether_quartz_ore','electric_spark 1 1 1 0.5'),
l('diamond_ore','dust 0.3 0.8 1.0 0.5'),
l('emerald_ore', 'dust 0.4 1.0 0.4 0.5')
);

__on_tick() ->
(
for (player('!spectating'), player = ;
item_mainhand = player ~ 'holds';
if(!(query(player, 'holds', 'offhand'):0 == 'torch'), return());
player_pos = pos(player);
l(x, y, z) = map(player_pos, floor(
));
player_in_caves = top('terrain',player_pos) > (y+3);
// modify reference Y level, around diamond level for surface tracking
base_y = if(player_in_caves, y, 8);
loop(360,
try (
l(block_x, block_y, block_z) = l(x, base_y, z)
+ l(rand(10)-rand(10), rand(10)-rand(10), rand(10)-rand(10));
block = block(block_x, block_y, block_z);
if (block ~ '_debris'||'_ore',
for(range(0, 7),
l(oreblock, ore_particle) = get(global_mineral_ores, _);
if (block == oreblock,
if( player_in_caves,
particle_line(ore_particle,
player_pos+l(0,1.2,0),
block_x+0.5, block_y+0.5, block_z+0.5,
0.8
)
,//else
particle(ore_particle,
block_x, top('terrain',block)+1 , block_z,
20
)
);
throw()
)
)
)
)
)
)
);

`

commented

Seems like Github broke formatting... Could you try pasting it again with triple ` at the start and end of the code block or uploading the script file?

```
code
```

commented

Ok, I also uploaded the reloading script.
https://github.com/leucome/Prospector_Torch

commented

May be because of the return() in line 33, it is returning from the entire function if the first player checked isn't holding the torch (should be continue() to process next entry in the list), though I still haven't properly tested it on a server seems to then work properly with bots in singleplayer.

Also side note, player('!spectating') will only return players from the dimension the call is coming from, and on_tick always uses overworld, so in order to check for debris (assuming you didn't change worldgen) you'd need to get nether players in an __in_dimension('nether', ...) inside the tick event.

commented

Thanks!
I tried with for (player('all') and also continue()
I still need to reload the script after login in. But now I can detect ore in spectator mode too.

Not sure why but it seem that on_tick combined with player('!spectating') is working for other dimension on my server. I was able to detect in nether and in other custom dimension.

commented

I'm experiencing the same issue. __on_tick() in a player scope app refuses to fire after reconnecting. Even after using the /<app> command directly. Worth noting that if I use /script load <app> the __on_tick() event resumes, working as expected.

I'm using fabric-carpet-1.18-1.4.56+v211130.

repro.sc:

__config() -> {'scope' -> 'player'};

// will always work
__command() -> print('I ran');

// will stop spamming chat when you reconnect, but reloading resumes the spam
__on_tick() -> print(player('all'), 'tick tock');

My workaround is to use an infinite schedule(0, 'fake_tick') loop to get ticks. I kick it off in both __on_player_connects() and __on_start(). Then at the end of fake_tick() I schedule fake_tick again.