0
Answered

Farming Game

Crispy 12 months ago in Game Creator updated by Marti (Lead Developer) 12 months ago 1

I'm trying to do the following and I'm finding I need so many actions and conditions:

- Clear dirt patch

- Get plant seed (picking one up from a set lying on the ground)

- Plant seed

- Water seed

- After some time, plant finishes growing

- Harvest crop


The reason it's so difficult is because I have multiple plants. What I'm doing right now is when I 'Get plant seed', I store a variable for what seed I have. Then when I plant, I check that variable. Depending on what seed I have, I perform a set of actions, which generally consists of 'Set Active a prefab on the dirt patch to represent first stage of crop growth' and 'Set a state to a local variable'. So if I have 8 different possible seeds I can plant, I'd need 8 different sets of actions. I'd also need 8 conditions saying 'If it's ____ seed', do '____ seed's Action'. Also, each time I interact with the dirt patch, I have to check what state it's in. Depending on the state (dry, watered, dead), I'd have to perform a different set of actions. This quickly gets very cumbersome.

Unity version:
Game Creator version:
1.0.3

Answer

Answer
Answered

Agree, but there are some things you can do to "share" code (Actions in this case) between different plans. Let's say you have a Fire Plant that takes 5 seconds to grow and gives you 3 Fire Seeds. Then, you also have a Water Plant that takes 10 seconds to grow and gives you 1 Water Seed.

You could have a bunch of Global Variables of type Game Object that reference the prefab objects of each plant. For example, global variable "fire-plant" would reference a Fire Plant prefab, and "water-plant" would reference a Water Plant prefab.

Now this is very useful because when you plant a plant, you simply instantiate a game object from the variable you want. You can have an "On Start" Trigger in each plant that will execute an Actions that waits a few seconds (5 for Fire Plant and 10 for Water Plant) and changes the 3D model onto one that looks like a fully blossomed plant.

You could also add a Local Variable "is-dead" to all plants as well as a "water-need" variable, that starts at different values depending on the seed. An "On Start" Trigger could start lowering the "water-need" at fixed timesteps, and if the value reaches 0, it changes the value of "is-dead" to true. Watering a plant would simply increase the "water-need" numeric variable.

The idea would be having each seed/plant as an individual prefab and everything work very systemic-wise. Moreover, you could also make use of the "Execute Actions" action, which allows you to execute an Actions component from a game object (that can come from a Local Variable).

If you have a particular thing you want to have explained, feel free to ask. This looks like a very interesting project

GOOD, I'M SATISFIED
Satisfaction mark by Crispy 12 months ago
Answer
Answered

Agree, but there are some things you can do to "share" code (Actions in this case) between different plans. Let's say you have a Fire Plant that takes 5 seconds to grow and gives you 3 Fire Seeds. Then, you also have a Water Plant that takes 10 seconds to grow and gives you 1 Water Seed.

You could have a bunch of Global Variables of type Game Object that reference the prefab objects of each plant. For example, global variable "fire-plant" would reference a Fire Plant prefab, and "water-plant" would reference a Water Plant prefab.

Now this is very useful because when you plant a plant, you simply instantiate a game object from the variable you want. You can have an "On Start" Trigger in each plant that will execute an Actions that waits a few seconds (5 for Fire Plant and 10 for Water Plant) and changes the 3D model onto one that looks like a fully blossomed plant.

You could also add a Local Variable "is-dead" to all plants as well as a "water-need" variable, that starts at different values depending on the seed. An "On Start" Trigger could start lowering the "water-need" at fixed timesteps, and if the value reaches 0, it changes the value of "is-dead" to true. Watering a plant would simply increase the "water-need" numeric variable.

The idea would be having each seed/plant as an individual prefab and everything work very systemic-wise. Moreover, you could also make use of the "Execute Actions" action, which allows you to execute an Actions component from a game object (that can come from a Local Variable).

If you have a particular thing you want to have explained, feel free to ask. This looks like a very interesting project