This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Godot 2.1 get current url of the game in GDScript

KevsakKevsak Posts: 4Member

Hi everyone.
I'm exporting my game for html5. i get the link to my game from my server, which gives some parameters (that i need in my game) beside the link. is it possible to get those parameters somehow? my link is: (serverpath)/game.html?sid=5edcf6-413477

(5edcf6-413477) is what i need


Tags :

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    If you can get the entire URL/Link, then something like this should get the sid value from the URL (untested):

    func get_sid(url_string):
        var sid_index = url_string.findn("sid=")
        if (sid_index == -1):
            print ("Error: SID not found!")
            return null
        else:
            # I don't remember if find gets the start, or the end.
            # I think it gets the start, so 4 characters (sid=) will need to be added
            var start_index = sid_index + 4
            var sid_string = ""
            while (start_index <= url_string.length()):
                var character_to_add = url_string[start_index]
                # If a new parameter has been started, then add the next character and move on
                if (character_to_add != "?" and character_to_add != "&"):
                    sid_string += character_to_add
                    start_index += 1
                # If a new parameter has started, then break the while loop
                else:
                    break
            return sid_string
    

    There might be a way to get the variable directly from Godot without having to parse the URL, but the above should, hopefully, work.

    Hopefully this helps!

  • KevsakKevsak Posts: 4Member

    Thanks for the reply, but my problem is to get the URL :)

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Ah, my bad!

    Unfortunately my HTML5 exports are not working, so I cannot actually test the code, but for Godot 3.0 the OS class might provide the required information. Specifically, these functions seem promising:

    print ("Command line args:");
    print (OS.get_cmdline_args());
    print ("Executable path:");
    print (OS.get_executable_path());
    print ("Name");
    print (OS.get_name());
    

    And it looks like Godot 2.1 has the same functions. I don't know if these will give the URL, but I couldn't find anything and these functions seem the most likely.

    It is rather strange there is not a function for this though. It might be worth opening a feature request, assuming one doesn't exist, on the Godot GitHub repository to have this functionality added.

    Anyway, my apologizes for misunderstanding and hopefully one of those functions returns the URL.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.