godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.11k stars 20.2k forks source link

OS.execute Not Working On Export #60948

Closed kimbunner closed 2 years ago

kimbunner commented 2 years ago

Godot version

v3.5.beta3

System information

Windows 10

Issue description

When I Was Debuging The Game Its Working But On Export It Doesnt Work

Steps to reproduce

Here Is My Code

extends Node2D

var directory = Directory.new()
var random_generator = RandomNumberGenerator.new()
var pic = 9
const minq = 0
const maxq = 8
var bg = false
var file2Check = File.new()
var i_name = ""
var i_ver = ""
var output = []
var com = false

func _ready():
    $bgt.start()
    random_generator.randomize()
    pic = random_generator.randi_range(minq,maxq)
    print(pic)
    if pic == 0:
        $bg.texture = load("res://ui/bg.jpg")
    if pic == 1:
        $bg.texture = load("res://ui/bg1.jpg")
    if pic == 2:
        $bg.texture = load("res://ui/bg2.jpg")
    if pic == 3:
        $bg.texture = load("res://ui/bg3.jpg")
    if pic == 4:
        $bg.texture = load("res://ui/bg4.jpg")
    if pic == 5:
        $bg.texture = load("res://ui/bg5.jpg")
    if pic == 6:
        $bg.texture = load("res://ui/bg6.jpg")
    if pic == 7:
        $bg.texture = load("res://ui/bg7.jpg")
    if pic == 8:
        $bg.texture = load("res://ui/bg8.jpg")

func _physics_process(delta):
    if com:
        if $console/text.text == "[]":
            $wait.visible = true
            $console.visible = false
            $add2.visible = false
            $add.visible = false
            $FileDialog.visible = false
        else:
            com = false
            $wait.visible = false
            $console.visible = true
            $add2.visible = true
            $add.visible = false
            $FileDialog.visible = false

    $console/text.text = str(output)

    if pic == 0:
        $bg.texture = load("res://ui/bg.jpg")
    if pic == 1:
        $bg.texture = load("res://ui/bg1.jpg")
    if pic == 2:
        $bg.texture = load("res://ui/bg2.jpg")
    if pic == 3:
        $bg.texture = load("res://ui/bg3.jpg")
    if pic == 4:
        $bg.texture = load("res://ui/bg4.jpg")
    if pic == 5:
        $bg.texture = load("res://ui/bg5.jpg")
    if pic == 6:
        $bg.texture = load("res://ui/bg6.jpg")
    if pic == 7:
        $bg.texture = load("res://ui/bg7.jpg")
    if pic == 8:
        $bg.texture = load("res://ui/bg8.jpg")

func _on_bgt_timeout():
    bg = false
    $AnimationPlayer.play("fade")

func _on_AnimationPlayer_animation_finished(anim_name):
    if bg == false:
        bgr()
        $AnimationPlayer.play("unfade")
        bg = true
    if bg == true:
        $bgt.start()

func bgr():
    random_generator.randomize()
    pic = random_generator.randi_range(minq,maxq)

func _on_add_pressed():
    if file2Check.file_exists("res://files.bea"):
        ProjectSettings.load_resource_pack("res://files.pck")
        if file2Check.file_exists("res://files.pck"):
            $name.set_script(load("res://file.gd"))
            i_name = $name.gname
            $game/gname.text = $name.gname
            $game.texture = load("res://" + $name.iname + "/gicon.png")
            print(i_name)
            $FileDialog.visible = true
        else:
            $error.visible = true
            $error/content.text = "files.Pck Cant Find :("
    else:
        $error.visible = true
        $error/content.text = "files.bea Cant Find :("

func _on_FileDialog_dir_selected(dir):
    OS.execute("UnRAR.exe", ["x","-p******","files.bea ", dir], true, output)
    $console.visible = true
    $add2.visible = true
    $add.visible = false
    $FileDialog.visible = false

func _on_add2_pressed():
    $console.visible = true

Minimal reproduction project

No response

Calinou commented 2 years ago

This is likely because UnRAR.exe is not located besides the project executable after exporting the project. Alternatively, this could occur because you're starting the executable in a way that doesn't change its current working directory to be the folder containing the project executable.

Also, you can't embed executables inside a PCK file. OS.execute() will not be able to run them if you do that, even if you specify *.exe in the non-resource export filter.

PS: Code blocks should use triple backticks like this (with an optional language name for syntax highlighting):

```gdscript code here ```

I edited your post accordingly, but remember to do this in the future :slightly_smiling_face:

kimbunner commented 2 years ago

Thanks Im Using Godot To Make My Repacks

kimbunner commented 2 years ago

@Calinou So Youre Right The UnRAR.exe Is Missing Where Can I Place That?

Calinou commented 2 years ago

@Calinou So Youre Right The UnRAR.exe Is Missing Where Can I Place That?

It needs to be placed in the same location as the exported executable. Also, double-check that antivirus programs are not preventing it from being run.