Beginner Coding

D

DessertTribes

Guest
I'm new at GML but I enjoy the way coding makes you think, so the first picture the highlighted line works fine. All I want is to right click to destroy crops, I made it so I left click to plant crops and it works out fine. I thought all I had to do was the opposite but I got stuck. I just need help to right click the mouse to destroy the instance.pc1.png pc2.png
 

rIKmAN

Member
I'm new at GML but I enjoy the way coding makes you think, so the first picture the highlighted line works fine. All I want is to right click to destroy crops, I made it so I left click to plant crops and it works out fine. I thought all I had to do was the opposite but I got stuck. I just need help to right click the mouse to destroy the instance.View attachment 25363 View attachment 25364
In your left mouse check you are creating an instance of "selectCrop" which I assume is the currently chosen crop, but in the right mouse check you are trying to destroy "spr_crops" which I would assume is the sprite.
 
D

DessertTribes

Guest
In your left mouse check you are creating an instance of "selectCrop" which I assume is the currently chosen crop, but in the right mouse check you are trying to destroy "spr_crops" which I would assume is the sprite.
Ya I'm trying to destroy the "spr_crops" I don't know how to destroy the instance "spr_crops" I think I have to set it up in the script that is in the second picture.
 

pipebkOT

Member
@DessertTribes but spr_crops is not an instance nor object, is an sprite!!

if you created an instance of the object obj_crop, and wanted to destroy it ,the logical thing to do would be to destroy the same object called obj_crop, not the sprite spr_crops ;)
 
Last edited:

rIKmAN

Member
Ya I'm trying to destroy the "spr_crops" I don't know how to destroy the instance "spr_crops" I think I have to set it up in the script that is in the second picture.
I'm assuming you are sticking to the usual naming conventions here and that the "spr_" prefix signifies that the resource is a sprite?
If so, then you can't destroy sprites, you need to destroy the instance of the object as you just said.

In the second image you create an instance and store it in a variable called "inst", and then you store that inside a grid (which I assume matches the position of the tiles or grid of your level).

So logically and working backwards from that, to destroy that instance you would need to find what cell of the grid the cursor is in when the right mouse button is clicked, and then with that information you can destroy the instance stored in that grid position.
if you created an instance of the object obj_crop, and wanted to destroy it ,the logic thing to do would be to destroy the same object called obj_crop, not the sprite spr_crops ;)
That would be logical by following the prefixes, but that would destroy every instance of obj_crops rather than the specific instance that was being clicked on.
 
Last edited:
Top