#I have a question

1 messages · Page 1 of 1 (latest)

vital haven
#

No, because you didn't share the code.
If you need help with code, you need to share the code.

soft rivet
#

extends Button

var exe_link = ""
var pck_link = ""
var version_link = ""

var exe_path = ""
var pck_path = ""
var version_path = ""

var http_request: HTTPRequest

func _ready():
_verify_gamefiles()
self.disable = true

func file_exitsts(path: String) -> bool:
var dir = Directory.new()
return dir.file_exists(path)

func _verify_gamefiles() :
#check if files are completed
if file_exists(exe_path) && file_exists(pck_path) && file_exists(version_path):
_download_version(version_link, version_path, true)
pass
else:
pass

#

func _download_file(link: String, path: String, just_version: bool):
http_request = HTTPRequest.new()
add_child(http_request)

self.text = "Downloading " + str(path.get_file())
http_request.connect("request_completed", self, "_install_file", [path, just_version])


var error = https_request.request_raw(link) 
if error != OK:
    self.text = "Download Error: " + str(error)

func _install_file(_result, _response_code, _headers, body, path, just_version: bool):

if just_version:
    var new_version = str(body.get_string_from_utf8())
    _compare_version(new_version)
    return
    
    
    var dir = Directory.new()
    dir.remove(path)
    
    var file = File.new()
    file.open(path, File.WRITE)
    file.store_buffer(body)
    file.close()
    _check_integrity()

func _check_integrity():
if !file_exists(exe_path):
_download_file(exe_link, exe_path, false)
print("no exe")
return

    if !file_exists(version_path):
            _download_file(version_link, version_path, false)
            var dir = Directory.new()
            dir.remove(pck_path)
            print ("no version")
            return
            
            self.text = "Start Game"
            self.disable = false

func _compare_version(new_version):
var file = File.new()
file.open(version_path, File.READ)
var cur_version = file.get_as_text();
file.close
if int(new_version) > int(cur_version):
var dir = Directory.new()
dir.remove(version_path)
_check_integrity()

func _start_game():
OS.shell_open(OS.get_user_data_dir() + "/myGame.exe")

func _on_Button_pressed():
_start_game()

vital haven
#

There's a typo in the function name here: func file_exitsts(path: String) -> bool:

But more importantly, why are you rewrite/reinventing the wheel when this exists: https://docs.godotengine.org/en/stable/classes/class_fileaccess.html#class-fileaccess-method-file-exists

soft rivet
#

what i need to replace basiclly that bool thing ?

vital haven
#

get rid of your own function and use the existing one

soft rivet
#

file_exists(path: String) static to use that ?

#

can u just edit that what i need to fix and send it