static_variables.gd 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. @static_unload
  2. static var perm := 0
  3. static var prop := "Hello!":
  4. get: return prop + " suffix"
  5. set(value): prop = "prefix " + str(value)
  6. static func get_data():
  7. return "data"
  8. static var data = get_data()
  9. class Inner:
  10. static var prop := "inner"
  11. static func _static_init() -> void:
  12. prints("Inner._static_init", prop)
  13. class InnerInner:
  14. static var prop := "inner inner"
  15. static func _static_init() -> void:
  16. prints("InnerInner._static_init", prop)
  17. func test():
  18. prints("data:", data)
  19. prints("perm:", perm)
  20. prints("prop:", prop)
  21. perm = 1
  22. prop = "World!"
  23. prints("perm:", perm)
  24. prints("prop:", prop)
  25. prints("other.perm:", StaticVariablesOther.perm)
  26. prints("other.prop:", StaticVariablesOther.prop)
  27. StaticVariablesOther.perm = 2
  28. StaticVariablesOther.prop = "foo"
  29. prints("other.perm:", StaticVariablesOther.perm)
  30. prints("other.prop:", StaticVariablesOther.prop)
  31. @warning_ignore("unsafe_method_access")
  32. var path = get_script().get_path().get_base_dir()
  33. @warning_ignore("unsafe_call_argument")
  34. var other = load(path + "/static_variables_load.gd")
  35. prints("load.perm:", other.perm)
  36. prints("load.prop:", other.prop)
  37. other.perm = 3
  38. other.prop = "bar"
  39. prints("load.perm:", other.perm)
  40. prints("load.prop:", other.prop)