dictionary.gd 974 B

12345678910111213141516171819202122232425262728293031323334353637
  1. func test():
  2. # Non-string keys are valid.
  3. print({ 12: "world" }[12])
  4. var contents = {
  5. 0: "zero",
  6. 0.0: "zero point zero",
  7. null: "null",
  8. false: "false",
  9. []: "empty array",
  10. Vector2i(): "zero Vector2i",
  11. 15: {
  12. 22: {
  13. 4: ["nesting", "arrays"],
  14. },
  15. },
  16. }
  17. print(contents[0.0])
  18. # Making sure declaration order doesn't affect things...
  19. print({ 0.0: "zero point zero", 0: "zero", null: "null", false: "false", []: "empty array" }[0])
  20. print({ 0.0: "zero point zero", 0: "zero", null: "null", false: "false", []: "empty array" }[0.0])
  21. print(contents[null])
  22. print(contents[false])
  23. print(contents[[]])
  24. print(contents[Vector2i()])
  25. print(contents[15])
  26. print(contents[15][22])
  27. print(contents[15][22][4])
  28. print(contents[15][22][4][0])
  29. print(contents[15][22][4][1])
  30. # Currently fails with "invalid get index 'hello' on base Dictionary".
  31. # Both syntaxes are valid however.
  32. #print({ "hello": "world" }["hello"])
  33. #print({ "hello": "world" }.hello)