Godot PGSGP Why can't I connect a function to the signal

111 Views Asked by At
extends Node

var client : NakamaClient
var session : NakamaSession
var socket : NakamaSocket
var username = "example"
var play_service


func _ready():
    if Engine.has_singleton("GodotPlayGamesServices"):
        play_service = Engine.get_singleton("GodotPlayGamesServices")
        
        play_service.init(true, true, true, "id")
        play_service.connect("_on_sign_in_success", self, "ConnectToNakama")
        play_service.connect("_on_sign_in_failed", self, "_on_sign_in_failed")
    play_service.signIn()


func _on_sign_in_failed():
    pass
func ConnectToNakama(profile):
    client = Nakama.create_client('defaultkey', "ip", 7351,
    'http', 3, NakamaLogger.LOG_LEVEL.ERROR)
    var split = profile.split('"')
    var id = split[11]
    session = yield(client.authenticate_device_async(id, username), 'completed')
    if session.is_exception():
        print("connection has failed " + session.exception.message)
        return
    
    socket = Nakama.create_socket_from(client)
    yield(socket.connect_async(session), "completed")
    
    print("Connected!")
    

on

play_service.connect("_on_sign_in_success", self, "ConnectToNakama")
play_service.connect("_on_sign_in_failed", self, "_on_sign_in_failed")

altough I do succesfully sign in, the ConnectToNakama function is not running also when i write play_service.connect("_on_sign_in_success",self,(suggestions appear)) if i remove the

play_service.signIn() 

the ConnectToNakama suggestion appears but the

func _on_sign_in_failed 

suggestion still doesn't appear

and I can't sign in if i put the

play_service.signIn()

in another function what can I do? :c

Godot 3.5.1 Stable

1

There are 1 best solutions below

6
Theraot On BEST ANSWER

The few things I can identify:

  1. singIn should be inside the if statement, here:

    func _ready():
        if Engine.has_singleton("GodotPlayGamesServices"):
            play_service = Engine.get_singleton("GodotPlayGamesServices")
    
            play_service.init(true, true, true, "id")
            play_service.connect("_on_sign_in_success", self, "ConnectToNakama")
            play_service.connect("_on_sign_in_failed", self, "_on_sign_in_failed")
    
            play_service.signIn() # <-
    

    That is because play_service would only be initialized if the execution entered the if statement.

    On a similar note: make sure the indentation is correct. You could not be getting the suggestions because of a syntax error, such as wrong indentation.

  2. The "_on_sign_in_failed" signal passes an int. I claim this based on the source code at PGSGP. Thus you should declare the _on_sign_in_failed method with a parameter:

    func _on_sign_in_failed(status):
        pass
    

    I'm guessing that ConnectToNakama is not running because it is trying to call _on_sign_in_failed instead, but that is also failing because it is missing the parameter.

  3. They should not be necessary, but these are the types for "_on_sign_in_failed":

    func _on_sign_in_failed(status:int) -> void:
        pass
    

    And for "_on_sign_in_success":

    func ConnectToNakama(profile:String) -> void:
        # …