The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hiy, is something like:
@export var array: Array[(String, Int)] = [("test", 5), ("a", 2)] possible with godot?

Longer Question:
I have a resource and want to export it, with a dynamically changeable int.

More Concrete:
I have effects for weapons (like damage something) and I want to be able to specify how much damage the item does. Because the item could also have effects like add armor and stuff like that I would like to store all effects & how much they scale in a Array and export it.


Bad Solutions:

  1. One could use 2 array and always fill them up that they mach each
    other. (Bad because error prone and hard to read)
  2. A Dictionary could be used one value is the Key (e.g. the resource
    effect) & the value is the scale. (Bad because Dict are untyped,
    malformed data could slip in)

If any one knows a better solution, I would really appreciate it!

Godot version 4.0
in Engine by (12 points)

1 Answer

0 votes

Custom resources.

https://docs.godotengine.org/en/stable/tutorials/scripting/resources.html#creating-your-own-resources

Create a Weapon resource that exports a string and int. In use, export the Array of type Resource (or the class_name).

by (1,406 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.