Hemiptera Bugtracker at bugs.linux-forks.de

advtrains

Access+to+wagon.train_id+in+on_joinplayer+callback+handler

Send replies to 192@bugs.linux-forks.de or using the Form below.
avatar From: OP
Sun, 12 Jun 2022 20:20:02 -0000

I+noticed+that+a+player,+who+was+on+a+wagon,

+and+joins+the+game+_while+the+wagon+is+already+loaded_,

+is+not+attached+to+the+wagon.

I+think+the+problem+is+this+section+of+code+inside+the+on_joinplayer+callback+handler:

local+id+=+blablah

...

for+_,wagon+in+pairs(minetest.luaentities)+do

if+wagon.is_wagon+and+wagon.initialized+and+wagon.train_id==id+then

wagon:reattach_all()

end

end

This+never+calls+reattach_all()+on+any+wagon,

+because+wagon.train_id+does+not+exist.

Instead,+advtrains.wagons[wagon.id].train_id+has+to+be+used.

If+I+change+the+code+to+the+following,+it+works:

if+wagon.is_wagon+and+wagon.initialized+and+advtrains.wagons[wagon.id].train_id==id+then

wagon:reattach_all()

end

avatar From: Someone else
Sun, 12 Jun 2022 21:20:01 -0000

Seriously? Plusses all over? I will try it again.

---

I noticed that a player, who was on a wagon,

and joins the game _while the wagon is already loaded_,

is not attached to the wagon.

I think the problem is this section of code inside the on_joinplayer callback

handler:

local id = blablah

...

for _,wagon in pairs(minetest.luaentities) do

if wagon.is_wagon and wagon.initialized and

wagon.train_id==id then

wagon:reattach_all()

end

end

This never calls reattach_all() on any wagon,

because wagon.train_id does not exist.

Instead, advtrains.wagons[wagon.id].train_id has to be used.

If I change the code to the following, it works:

if wagon.is_wagon and wagon.initialized and

advtrains.wagons[wagon.id].train_id==id then

wagon:reattach_all()

end

Reply