I'm almost getting it, but I still don't know where I might be going wrong.

0 favourites
From the Asset Store
It's here!
$2.48 USD
50% off
Creepy and nasty horror track. It's terrifying from the beginning till the end. Goosebumps guaranteed
  • I'm trying to create a harvesting system with an array, I'm close to getting it right but there's still something missing. Currently I can click on plot objects (planting areas) and they get selected, the player goes to the location but doesn't perform any action, just stays still.

    Code objective: The player can click on multiple plots (planting areas), which are highlighted with a white effect when selected. The character will perform the harvest in the order of the clicks, completing one action before moving on to the next.

    Final Revised Code:

    Event 1: Mouse -> Left button clicked on Terra

    Conditions:

    Terra -> isSelected = 0

    Actions:

    Terra -> Set animation frame to 1 (shows the effect).

    Terra -> Set isSelected to 1.

    ActionsArray -> Push back Terra.UID on X axis.

    Event 2: System -> Every tick

    Conditions:

    Player -> isBusy = 0

    ActionsArray -> Value at (0, 0, 0) > -1

    System -> Pick Terra by UID (ActionsArray.At(0))

    Actions:

    Player -> Set isBusy to 1.

    Player -> Find path to (Terra.X, Terra.Y).

    Event 3: Player -> On Pathfinding arrived

    Actions:

    System -> Wait 1.5 seconds (simulates picking).

    Terra -> Set isSelected to 0 (deselects the plot).

    Terra -> Set animation frame to 0 (returns to normal frame).

    ActionsArray -> Pop front on X axis (removes the processed UID).

    Player -> Set isBusy to 0.

    I don't know what I'm doing wrong, if anyone can help me I'd appreciate it!

  • Could you post a screenshot of the events?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sorry, I was busy with work. Thanks for any help!

  • After "Find path" you need to wait for "On path found" event and tell the player to move along the path. Or you can use "Wait for previous action to complete". See the official Pathfinding example.

    And check which objects are moved with pathfinding - Player or PlayerMove?

    Also, in event #4 you need to pick the Terra instance by UID, otherwise all of them will be deselected.

  • The PlayerMove object is responsible for movement, while PlayerPug is just the animated sprite that visually follows PlayerMove using the pin behavior

    It seems my code has a conflict, and the array isn't working as expected. When I click on a "terra" object (the terrain sprite), it gets visually selected as it should. However, if I click on another "terra" object while the player is already moving towards the first one, the second object gets selected too, but the player cancels the path to the first object and moves directly to the last one clicked.

    What I want is for the player to follow a task queue, like in The Sims. The player should first go to the initial "terra" object, perform the assigned action there, and only then move to the next "terra" object clicked, executing tasks in the order they were added to the queue.

    I’m sending another image of the event sheet with the player movement code and the array system, which apparently isn’t working. Thank you for your response so far.

  • There are lots of problems in your code. Avoid using too many non-triggered events (which can run on every tick). Especially event #5 - it will repeat about 60 times per second while the conditions are true, and because you have "Wait 1.5s" action, it will create lots and lots of delayed threads. They will continue running and will delete other records from the array, will change the player's state to not busy, and generally will break everything.

    Check out this example:

    dropbox.com/scl/fi/0mww2lb7mvq7zerfjtoct/PF_Stack.c3p

  • Thank you so mutch dop2000 for reply and the exemple, I will try to follow thouse instructions, Im not a code person, but I having fun, and you help me a lot! :)

  • No worries!

    And here is an example demonstrating why using "wait" in events that run on every tick is a bad idea:

    dropbox.com/scl/fi/9q36kmmj5hsos5y85f1j5/WaitSucks.c3p

  • I want to thank you, I'll send you some money as soon as I get paid, thank you so much :)

  • I just set up your code in my event sheet in the array section, and when I tested it, to my surprise, it didn’t work. This leads me to believe it’s conflicting with my code for moving the character using the behavior that’s already in place. When I click anywhere on the ground, the player moves, and I can’t remove this behavior. When I create a system involving moving the character with the same Pathfinder behavior, it causes a conflict with the current character movement code, right? How could I use your code to move based on the array without conflicting with the existing Pathfinder movement system? I’m not sure if I was very clear, but thank you!

  • Please post your current code.

  • I noticed that in your code, the player only moves if you click on the red sprites that act as sensors, but if you click on the white area, the player doesn’t move. In my case, it’s different because the player moves freely around the map. The movement by clicking on specific objects, like crops, for example, is an additional feature. This seems to be causing conflicts in the code. Thank you for responding!

  • You need another variable, say, isFarming - set it to 1 when specific objects are clicked, or 0 when there are no objects in the array and the white area is clicked.

    Here is the updated project:

    dropbox.com/scl/fi/u26zo0gbdwrcsbwy3fqip/PF_Stack2.c3p

  • I edited my code to match yours, tested it, and it still didn’t work. I tested it with my player movement system both enabled and disabled. Interestingly, when I tested your code in the structure you made, it works, but when I try to implement it in my system, it doesn’t work. If I disable my player movement code, leaving only your code, the player doesn’t move. If I enable both codes simultaneously, the player moves freely but doesn’t activate the sensors through the array.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)