godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

fix: validate with is_network_master is correct form.

Open rdcklinux opened this issue 5 years ago • 5 comments

has_method returns true even if node isn't the master is_network_master returns correct validation.

rdcklinux avatar Jul 14 '20 16:07 rdcklinux

I believe this is incorrect. has_method is used to make sure it's the right kind of object (i.e. not another physics object without that met6hod). Additionally, that function is called by puppets on the master, so it would actually prevent it from working.

Faless avatar Jul 20 '20 13:07 Faless

I believe this is incorrect. has_method is used to make sure it's the right kind of object (i.e. not another physics object without that met6hod). Additionally, that function is called by puppets on the master, so it would actually prevent it from working.

the method has_method doesn't work in this scope, when the game instance isn't master it's returning true too.

rdcklinux avatar Jul 20 '20 13:07 rdcklinux

I believe this is incorrect. has_method is used to make sure it's the right kind of object (i.e. not another physics object without that met6hod). Additionally, that function is called by puppets on the master, so it would actually prevent it from working.

it's possible or sense add this methods: is_master_method() and is_puppet_method()

rdcklinux avatar Jul 20 '20 13:07 rdcklinux

It is probably a good change.

The actual demo contains this:

bomb.gd-# Called from the animation.
bomb.gd:func explode():
bomb.gd-  if not is_network_master():
bomb.gd:    # Explode only on master.
bomb.gd-    return
bomb.gd-  for p in in_area:
bomb.gd:    if p.has_method("exploded"):
bomb.gd:      # Exploded has a master keyword, so it will only be received by the master.
bomb.gd:      p.rpc("exploded", from_player)
bomb.gd-
bomb.gd-

But the tutorial leaves the first three lines of explode implicit (which this pull-request is adding in, albeit in a different place). It might be a good idea to maybe instead include the whole definition of func explode(): in the tutorial?

This does not change the often-raised issue of authoritativeness, which might still exist (but should probably be addressed separately).

Meriipu avatar Jul 30 '20 17:07 Meriipu

perhaps it's just a matter of ANDing the two conditions?

if (p.is_network_master() && p.has_method("exploded")) {
    // Do the thing...
}

jonbonazza avatar Apr 29 '22 23:04 jonbonazza

Is this still relevant with the latest documentation as of 4.1?

Calinou avatar Nov 16 '23 11:11 Calinou