extends Node2D # The directory with user files is located at: ‘’%APPDATA%\Godot\app_userdata\‘’. var votes_path = "user://votes.txt" # Called when the node enters the scene tree for the first time. func _ready(): $Timer.start() # Launch timer load_votes) # Initial data load from the file print(OS.get_user_data_dir()) # Output of data on the current user directory # The function is called upon retrieving actions from Skylark SL Neo by the SLService node or manually. # params[0] - votes for the first candidate, params[1] - votes for the second candidate func _on_sl_service_action_received(name, params): if name == "vote": if params.size() == 2: # If the necessary number of parameters is passed, the value is written to the Label node, and the formula is used to calculate a new value for Margin Right of the MarginContainer node. $Variant1/MarginContainer/Percents.set_text(params[0]+" Votes ") $Variant1/MarginContainer.add_theme_constant_override("margin_right", (100-int(params[0]))*600/100) $Variant2/MarginContainer/Percents.set_text(params[1]+" Votes ") $Variant2/MarginContainer.add_theme_constant_override("margin_right", (100-int(params[1]))*600/100) # Function for reading votes from a text file. Supposedly, the first line of the file contains a numeric value of votes for the first candidate, and the second line for the second candidate, respectively. func load_votes(): var votes = [] if FileAccess.file_exists(votes_path): print("file found") var file = FileAccess.open(votes_path, FileAccess.READ) while not file.eof_reached(): # iterate through all lines until the end of file is reached votes.append(file.get_line()) file.close() _on_sl_service_action_received("vote", votes) else: print("file not found") return # The function is called at the end of the specified interval in the Timer node. func _on_timer_timeout(): load_votes()