Unable to load global singleton script after exporting game

Godot Version

4.2.2

Question

this is console.exe

res://scripts/global.gd is the global singleton script

this is my export config

Can you paste the script, it seems it will require extends Node as the first line.

this is all content in global.gd

extends Node

signal level_change(val)

const rows = 20
const cols = 10
const size = 25
const grid_size = 26
enum Tetromino { I, L, J, S, Z, O, T }
var bound_min_x = 270
var bound_max_x = 530 - 26
var bound_max_y = 560 - 26
var tetromino_init_pos = Vector2(400, 40)

var level = 1.0

var score_list = []
func get_score_list_from_config_file():
	var config = ConfigFile.new()
	var load_err = config.load('user://save.cfg')
	var list = []
	if load_err == OK:
		for section in config.get_sections():
			var s_score = config.get_value(section, 'score')
			list.append({"nick_name": section, "score": s_score})
	return list


const piece_coords = {
	Tetromino.I: [Vector2(-1, 0), Vector2(0, 0), Vector2(1, 0), Vector2(2, 0)],
	#-------------------------------------------------------------------
	Tetromino.J: [Vector2(1,1), Vector2(-1, 0), Vector2(0,0), Vector2(1,0)],
	#-------------------------------------------------------------------
	Tetromino.L: [Vector2(-1, 1), Vector2(-1, 0), Vector2(0,0), Vector2(1, 0 )],
	#-------------------------------------------------------------------
	Tetromino.O: [Vector2(0,1), Vector2(1,1), Vector2(0,0), Vector2(1,0)],
	#-------------------------------------------------------------------
	Tetromino.S: [Vector2(-1, 1), Vector2(0, 1), Vector2(0,0), Vector2(1, 0)],
	#-------------------------------------------------------------------
	Tetromino.T: [Vector2(0,1), Vector2(-1, 0), Vector2(0,0), Vector2(1,0)],
	#-------------------------------------------------------------------
	Tetromino.Z: [Vector2(0,1), Vector2(1,1), Vector2(-1, 0), Vector2(0,0)]
}

var data = {
	Tetromino.I: preload("res://Resources/i_piece_data.tres"),
	Tetromino.J: preload("res://Resources/j_piece_data.tres"),
	Tetromino.L: preload("res://Resources/l_piece_data.tres"),
	Tetromino.O: preload("res://Resources/o_piece_data.tres"),
	Tetromino.S: preload("res://Resources/s_piece_data.tres"),
	Tetromino.T: preload("res://Resources/t_piece_data.tres"),
	Tetromino.Z: preload("res://Resources/z_piece_data.tres")
}

var clockwise_rotation_matrix = Transform2D(Vector2(0, -1), Vector2(1, 0), Vector2(0, 0))
var counter_clockwise_rotation_matrix = Transform2D(Vector2(0,1), Vector2(-1, 0), Vector2(0, 0))

# 已经被锁定并未被消除的块
var pieces: Array[Piece] = []

when I run game in editor, game is running normaly. After exporting,it has can’t load script error

If you change these to load instead of preload will it give you a different error? my thinking is it is having trouble with these resources?

image


it doesn’t work,but it does look like global.gd has been found and loaded.

1 Like

Awesome, this is exactly what I was hoping for. Can you show your resources panel for exporting? How are you running the export? Does the executable have the pack file next to it?

I mean this one, specifically what is your Export Mode set to? Does it include your resources folder?

I do see a little bit of cyclical dependencies happening here though. Your PieceData requires knowledge of Global to get it’s Global.Tetromino enumerated type, but your Global(global.gd) requires knowledge of PieceData through the preloads. Maybe you can make another script or move the enumerated type to be PieceData.Tetromino?

1 Like





my language is chinese, hope you don’t mind

1 Like

Thank you for the screenshots, very helpful and understandable even in another language.

Ah I know why it’s failing to use load, the path must match exactly, including capitalization. Windows ignores case and forces this upon it’s applications, but when packed Godot does not ignore case.

load("res://Resources/...") # fails!
load("res://resources/...") # works, same capitalization as your filesystem.

However, I have edited my post to include what I believe will allow the preload method to work too.

1 Like

Looks like I made a very cheap mistake.I think I changed the filename during development. :sweat_smile:

1 Like

It’s a very annoying problem, hides until you are exporting! Thank you for the screenshots, we made short work of it!

1 Like

Thank you so very very very very much for taking the time to find me a bug.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.