How do I keep these fields independent?

0 favourites
From the Asset Store
This pack has plenty of options to help your game background & ambience sound come to life.
  • Hey Experts!

    I have three "fields" (sprites) that when you click on them, a menu appears with two images. When you click on one of the two images, a new object is placed. That works fine.

    The problem is, when I select A or B or C, only one field will change. If I click A, a crop shows up but when I click on B, the crop is deleted from A and is now in B. Same with C. Somewhere I'm missing the command/language to operate the fields separate, any suggestions??

    How would I do this?

    (here is what I have so far)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I understand what you are trying to do correctly, the problem is your last event is telling your game to delete all the cornplant2 and strawberry instances whenever you click on the corn image. You need specify which instance of these you want to delete when you want to replace them with a different crop.

    top level event:

    eg. on left button clicked on corn_image2

    layer "cropselection" is visible

    pick placement location instance with UID = whatever

    Sub events:

    if placementlocation is overlapping cornplant2 - destroy cornplant2

    if placementlocation is overlapping strawberry - destroy strawberry

    blank - spawn cornplant2

    - set selectedlocationID to -1

  • Good catch! I understand what you're saying as for the fix but am struggling to implement it.

    + Mouse: On Left button Clicked on Corn_Image2

    + System: Layer "CropSelection" is visible

    + PlacementLocation: Pick instance with UID SelectedLocationID

    -> PlacementLocation: Spawn CornPlant2 on layer "Crops" (image point 0) (create hierarchy: False)

    -> System: Set SelectedLocationID to -1

    ----+ PlacementLocation: Is overlapping CornCrops

    -----> (no actions)

    (in picture format)

    What am I doing wrong? I appreciate your help.

  • Also tried this but nothing appears (guessing it keeps getting deleted?)

  • you have the PlacementLocation and CornPlant2 reversed in the final event where you want to destroy the CornPlant2 instance.

    the way you have the event condition makes it "pick" PlacementLocation instances, but you want to pick CornPlant2 instances. So your Destroy CornPlant2 action destroys all of them since all are picked by default.

    so saying CornPlant2 is overlapping PlacementLocation will pick the instances you want since you already have the correct PlacementLocation picked.

    I would put all crops in a family, and give the family an instance variable called Location, and assign that variable when the crop is spawned. Then you can pick crops by their location.

  • I moved it to the above section and it solves the problem BUT accidentally clicking the field (sprite) will wipe out whatever was there which is not the ideal situation as it could take 10 minutes in game for the crop/object to "grow".

    I'll leave this alone until I get some feedback so that I don't spam this post. Thanks for anyone's help!

  • you have the PlacementLocation and CornPlant2 reversed in the final event where you want to destroy the CornPlant2 instance.

    the way you have the event condition makes it "pick" PlacementLocation instances, but you want to pick CornPlant2 instances. So your Destroy CornPlant2 action destroys all of them since all are picked by default.

    so saying CornPlant2 is overlapping PlacementLocation will pick the instances you want since you already have the correct PlacementLocation picked.

    I would put all crops in a family, and give the family an instance variable called Location, and assign that variable when the crop is spawned. Then you can pick crops by their location.

    I appreciate the explanation as it helps me learn C3!

    Testing now, will update accordingly.

  • you will probably want to add a TimePlanted instance variable, or maybe a countdown variable until the plant is full grown...

  • I think I got it!! Building off of your explanation, I used the existing family and tweaked the programming.

    Boom! Before I get too excited, is there any potential issue with that??

  • you will probably want to add a TimePlanted instance variable, or maybe a countdown variable until the plant is full grown...

    I like the way you think! Here's what I have for that..

  • Spoke too soon. So I can somehow select corn which triggers the corn to show up and if I click the field again and select strawberry, it will also show up with the corn. When I click the field a third time and select either corn or strawberry, then anything there is destroyed and whatever I selected shows up.

    How do I prevent two items showing up? I've been testing to prevent having to waste your time with a silly question but it's gone from fun to frustrating and I need any available help.

  • in your previous post, you are checking CornCrops Overlapping CornCrops. That should be CornCrops overlapping PlacementLocation

    I would place the code to set the Animation frame in the event that increments the growth variable since that only runs every second. The way you are doing it will work fine, but it has to calculate the frame every tick (60 times a second) and it wont be changing that often. The less unnecessary work you do, the faster your game will run (and use less battery if you are aiming for mobile).

  • I would give the PlacementLocation an instance variable "Filled" or "Planted" and set that when you plant something. Then before planting anything else check if that it set. Clear it when you harvest.

  • in your previous post, you are checking CornCrops Overlapping CornCrops. That should be CornCrops overlapping PlacementLocation

    I would place the code to set the Animation frame in the event that increments the growth variable since that only runs every second. The way you are doing it will work fine, but it has to calculate the frame every tick (60 times a second) and it wont be changing that often. The less unnecessary work you do, the faster your game will run (and use less battery if you are aiming for mobile).

    Thanks for catching both of those and how to fix! Going back to it.

  • I would give the PlacementLocation an instance variable "Filled" or "Planted" and set that when you plant something. Then before planting anything else check if that it set. Clear it when you harvest.

    I believe you are right and am going back to rework it. Invaluable insight, I appreciate it.

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