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

Okay... I didn't know how else to phrase that question but hopefully, my explanation will clear things up. So I have an entity in my world that gathers those green blocks called energy and transfers them to other blocks. Each colored block has an energy value higher than the other. The image below shows all 6 green blocks. Starting from the top, its energy values are as follows: 6, 5, 4, 3, 2, 1. The entity has text showing the state that it is in and the amount of energy it has. "t" stands for taking and "g" stands for giving. The system that I have in place right now doesn't actually place the right tile corresponding to the energy level but instead, it just removes the block and replaces it with dirt since the entity took the energy. I need help with implementing a system where the entity takes from the block and changes the tile to the appropriate one as well as when it gives. If any clairifications are needed please ask! enter image description hereenter image description here

Godot version godot 3.4.2
in Engine by (26 points)

1 Answer

+1 vote
Best answer

You mean entity is supposed to take 1 energy at a time and change the mined tile to the one corresponding with less energy ?

by (8,188 points)
selected by

Hey Inces, essentially yes, but when I implemented this I ran into a problem where the code that handled the tile changing instantly changed tiles all the way down to the dirt tile. I tried adding a system where the entity remembers which tile it interacted with but failed. Thank you for helping me again! <3

Ah ok, so You must have designed an iteration, that worked too fast, as it was based on time isntead of on action, like on move ?

I might have mentioned setget funbctionality in your previous questions. It will allow You to mark a movement action when new tile is approached. Next, You will be able to use this mark to trigger actions and checks.

var tile : Vector2 setget newtile

func process():
       self.tile = Tilemap.world_to_map(global_position)

func newtile(value)
     if value != tile :
           tile = value
           checkcollisions()

This last function will trigger once per new move action on grid. Checkcollisions is just an example, You can also insert some signal there. Basically You want to check for collisions in this place of code and if there are mineral spots - take 1 energy and set tile to corresponding one. It will happen once.

Thank you so much Inces!!!! It worked... again! I wrote a function called check_tile_type(arr : Array) which takes a get_neighbors() array and checks which ones are of the type NATURAL_BLOCK (the green blocks) and changes them only once. Can I ask how you decided to use this approach? I just want to know your line of reasoning. Thanks again!! <3

This is a common problem in programming to trigger actions by other actions. Setget is known sollution for all these situations, that are connected with change of variable. You will find yourself to use this approach all the time :). Advanced programmers are able to almost not use process() function at all, only signals, setgets and custom triggers.

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.