0 votes

Hello,
i´m working on a RTS game, and currently trying to understand the best way to represent the many in game resources.
I´m tempted to use simple variables (var wood=100) but even if it´s quite simple to code it, i dont like it for two reason:
1. I would like the resource variable to have more properties then the amount only
2. Writing a list of variable is not the top in case this list is modified or new resources are added (re-write all the code to include the new resource)

Do you know a better way I can accomplish it? Is there any node it can help me here?

in Engine by (1,514 points)

1 Answer

0 votes

Sounds like your looking for a dictionary

    var resource {
        name = "wood",
        str = 23,
        life = 10
    }

  print("Type: ", resource.name, " Strength: ", resource.str, "Lifespan: ", resource.life)

  if resource.life = 0:
      do stuff
by (47 points)

how does this work with multiple resources?
I mean, do i need to declare resource1, resource2, resource3, etc, or can i somehow use the same template and change the value only?
(sorry, i´m pretty noob on this kind of stuff, but i couldnt find anything on the forum)

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.