Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
Wrap your code in [code][/code] tags, so we can follow the logic flow.
Example:
Edited for clarification:
Whitespace is important in python for controlling program flow. If we can't see where the loops and conditionals end, we don't know which (if either) of these code blocks you intend:
... and as odd as it may seem, the results from those two code blocks will be quite different from one another.
Help us to help you by showing us the code you see in the game, rather than making us try to guess what you may have written.
Now... what is it that the code is doing that you don't want it to, or not doing that you do want it to?
after hours of research and thinking this is the code i have come up with to attempt to suit my needs however it still does not work properly for some reason.
ground never gets tilled and items never get traded for maybei i shoul create a sep function for trades and maybe the get_harvest() has some weird priority and i should llower it but thats all i can think of for now
till() turns turf into soil, or soil into turf. get_ground_type() returns the type of ground at that spot; it will be either Grounds.Soil or Grounds.Turf, but you're only ever checking to see if it's Soil, and tilling all the soil into Turf. This means you will never have soil, which is why carrots and sunflowers are never being planted. It looks like you either don't understand conditional statements, or don't understand what get_ground_type() is doing... either way, you're only ever turning soil into turf in your code.
In main(), you're immediately tilling every piece of soil into turf. This will destroy anything that was planted on soil (if you ever had any soil in the first place). You then check if you can harvest, but the only things left will be hay, bushes, and trees.
Watering() looks okay. If you don't have enough water tanks, you buy more; then you use one of them if the water level on the current square is too low. Perfectly cromulent.
In Planting()...
Hay doesn't need planting, it "just grows" if the ground type is turf... but you're trying to plant grass. I'm betting that's gonna cause problems, although it won't cause the grass to not grow, so at least there's that.
Now, for the trees...
The modulus operator (%) gives back the remainder after division.
examples:
- 1 % 2 = 1
- 2 % 2 = 0
- 25 % 2 = 1
- 26 % 2 = 0
To summarize, you can use "if (number % 2) == 1" to see if a number is odd.Trees don't like other trees right next to them. You seem to have figured that out, but you're checking an awful lot of things to figure out where to plant trees, probably because you didn't realize that "x + y" will be even if both numbers are even, even if both numbers are odd, or odd if only one number is even and the other is odd.
What this all comes down to is that you can simplify your "can I plant a tree?" math to:
You can't plant(Entities.Carrots) because you've got turf instead of soil. You've tilled all your soil into turf, because you don't understand how get_ground_type() works.
I don't know what your sunflowers section is doing, other than I can see that it isn't going to do anything except perhaps buying seeds, because there's no such thing as Items.Sunflower... Entities.Sunflower, yes, but you can't use num_items() on entities... and all of this is moot, because you try to till() your soil into turf again, after which you fail to plant sunflowers because it's the wrong ground type.
My perception and review:
As far as I can tell, this code doesn't do anything except move around, and maybe harvest the occasional bush, tree, or hay. It feels an awful lot like you have gotten "help" to get to this point in the game, without understanding what the code you've copied is doing... or why. Copying other people's freely-given work is perfectly fine, once you understand what the code does... but you will never learn to program by using other people's code without understanding what that code does.
This game builds your programming knowledge piece by piece, expanding on what you've already learned with the next piece. I think you've tried to skip the "learning" part... but "button mashing" isn't going to help you in this game.
Now, as to what I would do about all of this:
I would recommend starting a new save.
Don't panic! This is not a failure, it's just part of the learning process.
Programming is hard. Like, really hard. It makes your brain do stuff in ways it's not used to; in ways it doesn't want to. It's like learning to juggle, in a sense. One ball is easy. Two balls is a little harder, but still doable. But you have to learn to juggle three balls before you can do five balls and really look cool.
I believe you have too many balls in the air, and nearly zero understanding of what any of those balls do when you throw them... and that's pretty much never going to work.
So: Start a new save.
Go slow.
Unlock one thing at a time, making sure you understand what the new thing you unlocked does (and how it works) before you move on to the next thing.
Read all of the information provided when you unlock things, and try to figure out the ramifications of the new action or item you've unlocked before you run off to the next thing. You will need to understand how what you're doing will affect the things you do afterward.
I'm not being mean when I say this:
Don't bother bringing this current mess with you; it's obviously not your own code... and it doesn't work anyway. Take a few days to wrap your head around "program flow". Once you learn and understand both "programming principles" and how the functions we are given in this scenario work, you will beat the game. Once you have done so, take a look at this old code and realize just how much you didn't "get" at the time.
We've all been there, and I won't lie and tell you that it's easy. Learning hard things is hard... but it can be fun, and it will definitely be incredibly rewarding... once you've finally bashed your head into the wall (figuratively speaking) enough times for it to sink in.
A couple quick things:
To be fair, that previous paragraph may apply to me, too. That being said, I've been slinging code for nearly 40 years, so please do forgive any mild arrogance I may display.
As an example of move() being less useful as you progress in the game, I will share my movement function; it takes in an x and y coordinate, moves the drone to that position after deciding whether stepping off the edge of the map is faster than moving across the field, then performs a "scan" to get some information about what's in the position it just moved to.
Here's the relevant code (pulled from various source files, but hopefully complete):
(Tagged as a spoiler for obvious reasons, hover to see it)
(Note: This doesn't include any planting/harvesting code, because it's more fun to find those on your own)
Further Note: For those in a hurry, the relevant function itself is "move_to(target_x, target_y)". The rest of this wall of text is the supporting code that either calls that function, or makes it work (such as "is_moving_forward()", which checks that moving in one direction will result in a shorter "distance to target" than moving in the opposite direction).
Note 2: "scan()"ing every square I move to probably isn't the best way to do things, and rereading this code while I was grabbing the various pieces has shown me some refactoring targets... but my goal was "perfect vision" and "efficient movement". To be completely honest, I'm almost certain that doing it this way actively slows specific algorithms I've seen described in some "Let's Play" videos ("sunflowers by array" springs immediately to mind)... but it means I never have to think about what might or might not be underneath the drone when it arrives at a given square, because that information has already been gathered. Feel free to remove the "scan()" at the end of move_to(), and go on your merry way. Do be sure to grab is_moving_forward() on your way by, since move_to() in its current form doesn't work without it.
Note 3: I also always call scan() after changing the contents of a plot; ie, if I till, plant, harvest, water, or swap (although I stopped watering when I unlocked fertilizer). Yes, it costs a few ops to do so, but it keeps everything up-to-date; I feel the accuracy is more important at this phase in my journey toward "beating the game".
Note 4: This is probably an overly-large chunk of code to explain my point... but I wanted to show how it was used, as well as what it was doing. Sorry for the resulting wall of text.
my movement is fine im quite happy with it, it does what i needs to do, what i am unhappy with is why my conditionals arent working
this is solid code but i have to unlock lists to make this function this will serve as a great refrence point for the future ty.
discord mod ahhh reply, writing so much extra ♥♥♥♥ to get the same results
How well does the movement code you shared handle sunflowers?
Care to race? We plant a full 10x10 grid of sunflowers; first one to clear the field by harvesting the flowers in the correct order wins... no fair saying you cleared the field because the first sunflower you harvested destroyed them all.
For that matter, how are you handling the Maze levels at all if you're only moving North and East?
Now that I think about it, I suppose my entire comment boils down to "tell us you haven't figured out how to beat the game without saying you haven't beaten the game"... or maybe "Try again when you get past pumpkins."
nowhere did I say i only move north and east, I offered the newbie a solution he can understand very easily. Just going to block your snarky discord mod ahhh elitist attitude.