Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Autonauts

Make and teach robots to automate the world! · By Denki

Most Efficient Code For Storing/Picking up Items? Version 19.2

A topic by BLACKBERREST3 created Nov 06, 2017 Views: 2,204 Replies: 2
Viewing posts 1 to 3

So I have had this dilemma for quite a while now back since the early days of Autonauts. Let me give you an example of some code that I have come up with first. 

It's too long for 1 picture alone.


When the code runs, picking something up from the ground is much slower than picking up an object from a storage container. The reason for this has to do with the way the bots try to find items. If I try to take out the "Find Nearest..." command, the bot will not pick up the item. This adds a slight delay to the actions. The mechanics that I have observed for Autonauts is that for every line of code you add, this adds a 1-tick delay. For every "Repeat Until..." function you add, there is a negligible delay; probably around 1-2 milliseconds. Just minimizing the amount of code will not save you time however. I found that filling the bots inventory/hands between deliveries/stows save a significant amount of time. In order to maximize efficiency, some features may be needed.

1. Bots should remember the "Find Nearest..." command that was last played. This should get rid of a few lines of code. I am not sure if "global" commands will be implemented in the future or not, in which case that  feature might override this one.

2. Cycling should stack similar items. This would reduce the amount of times you would have to cycle the same item to empty your inventory.

If anyone has found a different technique that is just as fast and uses less code or is faster in general, then I am all ears.

Here is what I have managed to come up with.  I used your idea for the beginning to only stow items once hands are full, thank you for sharing that!  It would be neat if there was a way to fill up your hands from the inventory before unloading into a storage, but it's not really needed since either way, you'd have to cycle through items to fill up your hands...

Cool, thanks for responding tiffdud. I don't know how long it's been since I last posted, but if everything is still the same since my last post then this is still current. There could be a theoretical debate of less code vs efficient code, but for my sake I am going towards the most efficient because I do not like waiting very long and also because the game does not run in the background for me. The code you have is very neat and tidy, but because of current game mechanics, every time it loops (from various parts) in your code, more time is taken to do the actions assuming everything is output in one stack (if it isn't then the move command would be necessary). Clarifying just in case; If items are in one stack or the same place, then the bot does not need to move to keep picking up the items. I gave the example of bots remembering the last find nearest command or global variable as a solution for that exact reason. The game runs its code in ticks and so my goal is to have the code run in the least amount of ticks. The reason I want the hands to fill up before the stow command is because it uses less ticks. Examples:

With stacking - Cycle - Cycle - Cycle - Cycle - Stow (5 ticks - 4 items)

Without stacking - Cycle - Stow - Cycle - Stow - Cycle - Stow - Cycle - Stow (8 ticks - 4 items)

I noticed when comparing our codes that I could delete the very last repeat until hands empty command not that it would make a difference though because yours is still milliseconds faster and neater too on the second half of the code past the move to command. thanks for that.