extends Node
var Bank = 0
var Cookie = 0
var CookiePerClick = 1
var Clicked = 0
var CookiePerSecond = 0
var save_path = "res://savegame.save"
func load_game():
var file = FileAccess.open(save_path, FileAccess.READ)
Cookie = file.get_var($"/root/Global".Cookie)
func save_game():
var file = FileAccess.open(save_path, FileAccess.WRITE)
file.store_var(Cookie)
func _ready():
load_game()
while true:
$"/root/Global".Cookie += $"/root/Global".CookiePerSecond
await get_tree().create_timer(1).timeout
save_game()
it gives me an error "Attempt to call function 'get_var' in base 'null instance' on a null instance" when running my game, it crashes, does anybody understand why? (edited)func load_game():
var file = FileAccess.open(save_path, FileAccess.READ)
Cookie = file.get_var($"/root/Global".Cookie)
file
is null
, which would indicate that the file could not be opened successfullyBlock
(it contains vector of statements and symbol tablerunning: env -u IPHONEOS_DEPLOYMENT_TARGET "c++" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-Wall" "-Wextra" "-std=c++11" "-o" "/Users/john/Desktop/Development/ddnet-insta/build/release/build/cxx-06d76dbfffd32258/out/src/cxx.o" "-c" "src/cxx.cc"
cargo:warning=In file included from src/cxx.cc:1:
cargo:warning=src/../include/cxx.h:2:10: fatal error: 'algorithm' file not found
cargo:warning= 2 | #include <algorithm>
cargo:warning= | ^~~~~~~~~~~
cargo:warning=1 error generated.
exit status: 1
Block
(it contains vector of statements and symbol table running: env -u IPHONEOS_DEPLOYMENT_TARGET "c++" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-Wall" "-Wextra" "-std=c++11" "-o" "/Users/john/Desktop/Development/ddnet-insta/build/release/build/cxx-06d76dbfffd32258/out/src/cxx.o" "-c" "src/cxx.cc"
cargo:warning=In file included from src/cxx.cc:1:
cargo:warning=src/../include/cxx.h:2:10: fatal error: 'algorithm' file not found
cargo:warning= 2 | #include <algorithm>
cargo:warning= | ^~~~~~~~~~~
cargo:warning=1 error generated.
exit status: 1