Get Highscore submitting to GameJolt working.

MithosMoonMithosMoon Posts: 17Member

Hallo,
in the third level of my Game "Hoover-Buddy's Pixel Adventure" the player has 60 seconds to catch as much cheese-cake as possible.
After Timer ends, a rect is set visible and shows the score in a label. This all works fine.

I added the GameJoltAPI, with my key and Game_ID to the scene and a label for Player Name entering as well as a Button to submit the score and Name placed on the rect.

Now I want the score uploaded to Gamejolt, when someting is written in the label and the button gets pressed, but I need help for it.
Does anyone have an Idea how to make this working?

Answers

  • MegalomaniakMegalomaniak Posts: 1,059Admin
    edited November 2018

    I might be wrong on this but looks like the gamejolt api plugin was developed for godot version 1.2 and might need to be updated for it to work with godot 3. I've never used it though so not sure I can be of any real help.

    https://github.com/ackens/-godot-gj-api

    Latest commit seems to be from January 12th this year and was a fix to update it from godot version 1.2 to godot version 2.

    Are you using godot verions 2 or 3? I'm guessing 3.

    Couple of tutorial links(looks to be the same tutorial though) for using the gamejolt api plugin(both from march 2017):
    https://steamcommunity.com/sharedfiles/filedetails/?id=895167590
    https://www.gamedev.net/articles/programming/general-and-gameplay-programming/how-to-implement-scoreboards-in-godot-with-the-gamejolt-api-r4640/

    edit: ah here we go, someone submitted an issue on github for it where they linked to a pastebin commenting fixes for godot 3 use:
    https://github.com/ackens/-godot-gj-api/issues/3

  • MithosMoonMithosMoon Posts: 17Member

    Thank you for your answer.
    I am using Godot 3.
    I will have a look at the links and write later :)

  • MithosMoonMithosMoon Posts: 17Member
    edited November 2018

    Well I am using gamejolt_api_v2 and I thought this was the version to work with Godot 3. I backed up the main.gd from v2 and replaced it with the pastebin code.
    But my main problem is that I do not know to get things connected. Button, API, Label (with the score) and LineEdit.

    I found a youtube Video
    but this is spanish (I am German) I will see what I can understand :)

    EDIT:

    Thanks to this Video I have come a huge step further. This is for Godot 3 and GameJoltAPI v2 works with it's original script.

    So first I separated the API from the scene and put it into a new scene
    Next I work on my level script:

    First I set the Button disable false after a change in the LineEdit (signal from the LineEdit):

    func _on_LineEdit_text_changed(new_text):
    get_node("Player/Camera2D/highscoretable/submitbutton").set_disabled(false)

    Than I load the new scene via my global setScene variable(signal from the Button):

    func _on_submitbutton_pressed():
    get_node("/root/globals").setScene("res://uploadscore.tscn")

    Here I have set up a test string in the script (signal from the api):

    func _on_GameJoltAPI_api_session_opened(success):
    $GameJoltAPI.add_score("12 test", 128, "MithosMoon", "MyToken")

    ... and get the precoded data uploaded.

    But now I have to get the string working, with getting the texts from the labels ingame and make the Guest working, so everyone can upload the score.
    And this is where my journy ends at the moment xD
    So I still need help ^__^

  • MithosMoonMithosMoon Posts: 17Member
    edited November 2018

    I got the guest working, but instead of the Nickname entered, it shows the path to the LineEdit:

    the code in the gdscript to get this result is:
    func _on_GameJoltAPI_api_session_opened(success):
    guest_name = get_node("Player/Camera2D/highscoretable/LineEdit")
    $GameJoltAPI.add_score("12 test", 12, "", "", guest_name, 386278)

  • MegalomaniakMegalomaniak Posts: 1,059Admin
    edited November 2018

    Need to add .name to get the node name instead of the node path, I believe.

    func _on_GameJoltAPI_api_session_opened(success):
        guest_name = get_node("Player/Camera2D/highscoretable/LineEdit")
        $GameJoltAPI.add_score("12 test", 12, "", "", guest_name.name, 386278)
    

    Though looking at it again, perhaps you want to get the LineEdit value instead. So replace .name with .text I guess.

  • MithosMoonMithosMoon Posts: 17Member

    thx Megalo
    but this gives me an error: Invalid get index 'name' (on base: 'null instance').

  • MithosMoonMithosMoon Posts: 17Member

    Well I guess I have to do something with this line:

    guest_name = get_node("/root/World3/Player/Camera2D/highscoretable/LineEdit")

    to make the script grab the text that is written inside the LineEdit

  • MegalomaniakMegalomaniak Posts: 1,059Admin
    edited November 2018

    That probably means the node to be assigned to guest_name has not been created yet at the time your function runs. Use an if statement to make sure the node exists first.

    though in this case it's probably best to do something like:

    func _on_GameJoltAPI_api_session_opened(success):
        guest_name = get_node("Player/Camera2D/highscoretable/LineEdit")
    
        if guest_name != null:
            $GameJoltAPI.add_score("12 test", 12, "", "", $guest_name.text, 386278) 
    

    Note that i wrote that by hand here in the forum post editor and haven't tested it in engine, but it should be about right.

    edit: yeah I forgot the $ sign in front of guest_name in my last example. It printed the node path as string for you since the get_node gets the node path.

  • MithosMoonMithosMoon Posts: 17Member

    Now I get

    which might be a little better than the path, but shows that the Variable guest_name still is null.

  • MegalomaniakMegalomaniak Posts: 1,059Admin
    edited November 2018

    and did you change the actual EditLine in the in-game UI? Might also want to give it a default value.

  • MithosMoonMithosMoon Posts: 17Member

    the node is still not found

    0:02:00:0623 - Node not found: /root/World3/Player/Camera2D/highscoretable/LineEdit

    Type:Error
    Description: Node not found: /root/World3/Player/Camera2D/highscoretable/LineEdit
    Time: 0:02:00:0623
    C Error: Condition ' !node ' is true. returned: __null
    C Source: scene/main/node.cpp:1524
    C Function: get_node

  • MithosMoonMithosMoon Posts: 17Member

    I have an Idea:
    Now the API is in a new scene, loaded when button is pressed.
    Maybe I should put the API in the same scene, where the player enters his name, to be able to get the nodes?

  • MegalomaniakMegalomaniak Posts: 1,059Admin
    edited November 2018

    Maybe, or maybe it(the API scene) should be a singleton that you can call from your scene.

    What you should probably do is give a script to your highscore table then connect a signal from the submit button to the script and call the API submit function from within this new function that was created for the signal. Makes sense?

  • MithosMoonMithosMoon Posts: 17Member

    yeah sure. It works implemented the easy way now, within the same scene. Easy way means I just used the placeholders, but try to insert the IF Query now, to see if the text is found.

  • MithosMoonMithosMoon Posts: 17Member

    @Megalomaniak said:
    and did you change the actual EditLine in the in-game UI? Might also want to give it a default value.

    yes it has a default value, made it a placeholder:

    that it looks like this ingame:

  • MithosMoonMithosMoon Posts: 17Member

    nigher the label2 text, which holds the score, nor the Gueat name LineEdit gets ever found in the string :/
    only the direct test values are uploaded.
    I just do not understand this. I mean it is all in the same scene now and I can set the variables via $.

    It's a mistery to me, should be easier to manage.

  • MegalomaniakMegalomaniak Posts: 1,059Admin
    edited November 2018

    how about you try not using the placeholder and actually set a default starting value to the field you read from?

    Also try both $guest_name.text and guest_name.text in the add_score

  • MegalomaniakMegalomaniak Posts: 1,059Admin

    @Megalomaniak said:
    Also try both $guest_name.text and guest_name.text in the add_score

    yeah, derp on my part. I forgot you need to add the prefix of either get_ or set_ :#

    so guest_name.get_text not just .text

  • MithosMoonMithosMoon Posts: 17Member
    edited November 2018

    I still get "Invalid get index 'get_text' (on base: 'null instance')." ....Well I guess the node gets not found, because I have to insert some dots in the path line ".. But I don't know how many :/

    this is the tree:


    The script to call the text is the one attached to the Node "Main" which is parent of The API
    I also renamed the LineEdit to guest_name

    Thank you very much for your help so far

  • MithosMoonMithosMoon Posts: 17Member

    Does your Idea mean that I can forget about the variables when getting text directly in the add.score line?

    extends Node
    
    var guest_name = ""
    var score = null
    
    func _ready():
        pass
    
    
    func _on_submitbutton_pressed():
        $GameJoltAPI.open_session()
    
    func _on_GameJoltAPI_api_session_opened(success):
    
    
        score = get_node("./Player/Camera2D/highscoretable/label2")
        guest_name = get_node("./Player/Camera2D/highscoretable/guest_name")
        $GameJoltAPI.add_score("Cheesecake", 25, "", "", $guest_name.get_text, 386278)
        #if guest_name != null:
    
    
    
    
    func _on_GameJoltAPI_api_scores_added(success):
        print("score added")
    
  • MithosMoonMithosMoon Posts: 17Member

    I tried something, but still the same error

            extends Node
    
            #var guest_name = ""
            #var score = null
    
            func _ready():
                pass
    
    
            func _on_submitbutton_pressed():
                $GameJoltAPI.open_session()
    
            func _on_GameJoltAPI_api_session_opened(success):
    
    
                #score = get_node("./Player/Camera2D/highscoretable/label2")
                #guest_name = get_node("./Player/Camera2D/highscoretable/guest_name")
                $GameJoltAPI.add_score("Cheesecake", 25, "", "", get_node("./Player/Camera2D/highscoretable/guest_name").get_text, 386278)
                #if guest_name != null:
    
    
    
    
            func _on_GameJoltAPI_api_scores_added(success):
                print("score added")
    

    still get the error: "Invalid get index 'get_text' (on base: 'null instance')."

  • MithosMoonMithosMoon Posts: 17Member
    edited November 2018

    Yeah!
    with two dots in the line I get a different Error:
    Invalid get index 'get_text' (on base: 'LineEdit'). Did you mean '.get_text()' or funcref(obj, "get_text") ?

    I do not understand it, but I guess it means, that the LineEdit at least is found now.

    EDIT:

    Double Yeah!
    Now the guest name gets added correctly to GameJolt :smiley:

    I only had to add those () to .get_text

    Now I have to make the score working, which has to be get from a label.

  • MithosMoonMithosMoon Posts: 17Member
    edited November 2018

    It works

    No Variables needed, add.score line looks like this:

    $GameJoltAPI.add_score(get_node("../Player/Camera2D/highscoretable/label2").get_text(), get_node("../Player/Camera2D/highscoretable/label2").get_text(), "", "", get_node("../Player/Camera2D/highscoretable/guest_name").get_text(), 386278)

    Thank you very much for your help ... Now, soon I will upload version 0.2.0 :smiley:

Sign In or Register to comment.