Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Autonauts

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

¨IF¨ statement example

A topic by eloy2030 created Sep 11, 2017 Views: 2,946 Replies: 11
Viewing posts 1 to 12
(1 edit)

I thought of a good example of how to use the ¨if¨ statement. (at leas I think so)

Sometime when having multiple robots collecting the same (plantable) thing (tree seeds, cereal, apples) Production would be interrupeted because the thing that needs to be picked up is the same thing u need to be able to pick it up.

ie. If bot doesn't plant because his hands are not full no more tree will grow and he will have nothing to collect.

so, ¨if (item) is not in range¨  or ¨if storage is empty¨ would come in handy here. 

Edit: We might need an ¨end¨ statement as as well, to move out of the loo... or something similar.

(1 edit)

I'm not against a IF statement, but in your case you just need to put those things in a 'do until hands full' and/or  'do until hands empty'.

I feel like a "Do Until Stuck" would be a far more useful and easier to implement solution to most of the examples of wanting an If statement.

Using Do Until Stuck you could plant apple seeds as long as there were holes for seeds; and then start putting them away. Without trying to craft a balance of bots re-planting apple seeds and bots stowing them.

You could actually use Do Until Stuck to emulate most IF statements you'd want to create. - Give me an example of an IF and i'll show you how :).

(This is actually a practice i made when programming IRL; in highly nested loops sometimes avoiding if statments to reduce processing is good.)

- Clarification: - Do Until Stuck would attempt to do the things inside; until the robot would put that timer over his head. Instead of putting the timer over his head; he'd skip the loop. Edit: It could also be called Do Until Waiting if that makes more sense :).

I agree with the ¨stuck¨ part... but I cant use until hands full or empty if there are no seed on the ground... thats the main problem. 

It would just get stuck, that´s why I agree with that...

I´m thinking that most of my probles could b solved with ¨until storage empty/not empty¨

Well, until storage full/empty already exists.

What do you have now? Maybe I can help with the tools we have already.

hands full/empty

inventory full/empty

storage full/not full

I mean; you're having a bot / bots that's stalling your production. What's his code? And we can trouble shoot it. - if you'd like.

(1 edit)

the code is this

...and the problem happens when (if) somehow there are no more trees to cut and no more seeds lying around... can u think of an (automated) solution for that with the available tools?

tks!

edit: if the ¨until storage is empty/not empty¨ option would be available, I could have one bot deliver to storage, and only pick until ¨storage is empty¨

something like this (but change ¨until inventory empty¨ for ¨until storage empty¨

hope it makes sense.

(+1)

I was about to answer; but then I saw this post:

https://itch.io/t/142150/steambot-loop-example

Which goes into further detail.

Basically the main part you're after is the Until X Storage full > Wait. (Myself I add a move command, just cuz it's cool to have your workers standing in nice spots :D).

Check his post out; lmk if he covers it. The concept is to basically word your conditions backwards and put them inside your main loops.  (This is pretty common practice when programming)

(2 edits)

no, that doesn´t take the bot out of the collection loop... I want to get him out of the collection loop if there are no more seeds to pick or if the storage is empty... afaik, theres now way to do that now, hence, the post


or am i missing something?


edit: the example u provide (from the post) actually does take the bot out of the collection loop. Problem, is this is VERY inefficient. I want to break the loop ONLY when the storage is empty, not every time it is not full. That way I would need more bots to make the same task, which is what I want to avoid. (in may case, having to open the bot to take the seeds out, in any case, more work)

You're right, I don't know a way) to only do it when it's empty.

But the way "Full" works starts at like 95% full. And everything works pretty well when working with full storage.

"inefficient" is clearly objective. As I consider my set up to be fairly efficient, while using storage containing thousands of logs.

Bot's waiting at an empty log storage to grab a log to make the next thing (like planks) sounds inefficient to me. - But now, perhaps i'm the one missing something. :).

i also think that empty storage is definitively inefficient.  but I was aiming more at the ¨build more than u need¨ range...


tks, anyway!