D5: Made Godot scripts runnable from the command line

This commit is contained in:
Logan G 2023-12-06 01:23:40 -07:00
parent b9a86c612c
commit 9a2564986b
Signed by: logan
GPG key ID: E328528C921E7A7A
2 changed files with 59 additions and 55 deletions

View file

@ -1,6 +1,7 @@
#!/usr/bin/godot -s #!/usr/bin/godot -s
#d5p1.gd #d5p1.gd
extends Node3D #extends Node3D
extends SceneTree
enum Maps { enum Maps {
seeds, seeds,
@ -76,7 +77,7 @@ func map_input(data, seed):
func _init(): func _init():
print("Hello!") print("Hello!")
var temp = file_load("res://input.txt").split("\n\n") var temp = file_load(OS.get_cmdline_user_args()[0]).split("\n\n")
input_clean(temp) input_clean(temp)
var input = input_format(temp) var input = input_format(temp)
@ -97,3 +98,4 @@ func _init():
minval = location minval = location
print("Answer: %s" % minval) print("Answer: %s" % minval)
quit()

View file

@ -1,6 +1,7 @@
#!/usr/bin/godot -s #!/usr/bin/godot -s
#d5p2.gd #d5p2.gd
extends Node3D #extends Node3D
extends SceneTree
enum Maps { enum Maps {
seeds, seeds,
@ -91,7 +92,7 @@ func revmap_input(data, location):
func _init(): func _init():
print("Hello!") print("Hello!")
var temp = file_load("res://input.txt").split("\n\n") var temp = file_load(OS.get_cmdline_user_args()[0]).split("\n\n")
input_clean(temp) input_clean(temp)
var input = input_format(temp) var input = input_format(temp)
@ -113,6 +114,7 @@ func _init():
if seed >= seeds[i*2] && seed <= seeds[i*2]+seeds[i*2+1]: if seed >= seeds[i*2] && seed <= seeds[i*2]+seeds[i*2+1]:
print("Answer 2: %s" % testlocation) print("Answer 2: %s" % testlocation)
print("Value is between seed %s and %s" % [seeds[i*2], seeds[i*2]+seeds[i*2+1]]) print("Value is between seed %s and %s" % [seeds[i*2], seeds[i*2]+seeds[i*2+1]])
quit()
return return
testlocation+=1 testlocation+=1