Loading file from singleton on mobile does not work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By marcorexo

Hi,

I have a global script (globals.gd) loaded using AutoLoad under ‘project Settings’. This script, in turn, loads a text file (data.txt) in the same project directory, the contents of which are displayed using a label node.

The problem:
Running the app on the desktop works, showing the contents of the data.txt file. However, running on a mobile device shows ‘null’ as the label text i.e. the global script loads but the data.txt file is not opened.

Here’s part of the source code:

globals.gd autoloaded script:

func _ready():
	file = File.new()
	if file.open("res://data.txt", File.READ) != 0:
    	print("Error opening file")
	else:
		print("opened file") 

func get_file_content():
	var d = file.get_var()
	return d

A scene script that accesses the gloabls.gd variables:

func _ready():
	globals = get_node("/root/globals")
	get_node("lbl_data").text = str(globals.get_file_content())
:bust_in_silhouette: Reply From: volzhs

Fill filters (*.txt) at Export > [Target platform] > Resources > Filters to export