![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Agentfox |
Hi, I’m working in Godot 3.1 and am somewhat new to Godot. For my project, I’m making a space RTS where there are planets that you can build ships on.
A key part of this game is that a fleet is a grouping of ships.
Every planet stores the ships docked in a dictionary and what fleets they belong to in a seperate dictionary. I want to have buttons for every ship that give you the fleet they belong to when you click on them. To do this I have 2 dicts, shipsDocked
, and shipToFleetIndex
, which uses the same keys as shipsDocked
, but with fleets rather than ships.
For example: if shipsDocked
is {1:corvette, 2:freighter, 3:freighter}
and shipToFleetIndex
is {1:fleet1, 2:fleet1, 3:fleet2}
it means the corvette and freighter both belong to fleet1, but the other freighter belongs to fleet2.
Right now if I use this method to try and find the fleet (in this example), it would say both freighters belong to fleet1, because I used a for loop to find the key by the value, so it stops at the first freighter.
Is there any way to check for duplicates in a dictionary and then search the entire dictionary, rather than stopping at the first key?
I also would appreciate some insight into if there is a better way to do this than how I have it set up as I am a beginner.
Thanks in advance!