trash bin like node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ColdCoffe

how do you make something like a trash bin on desktop?
so when you drag items over the icon, the item will disappear.

i tried use an area2d and area detection from trash bin to each item, set a variable for each item, set them to false, then when area from one of the item collide with the trash bin and mouse button released, the item does disappear, all of them.

what did i do wrong?

If I understood you correctly, you want your items disappear when their collider collides with bin’s collider. I don’t get why you wanna have a variable on them, why no just simply queue_free() them?
Maybe if you show some code we understand better?

KijeviGombooc | 2019-07-25 11:36

Thank you before for the reply,

Basically, i want to create a cashier like simulation game, with simple gameplay mainly,
scanning the goods of the customer, put them into the bag, and get the money.

  • As for the node, it looks like this
    Screenshot by Lightshot

  • As for the variable, i thought that i can simply use .hide() and .show() to consider them finish, also as a signal to the objective? so the game can define whether player put the correct price for the correct goods. Anyway each of the goods have pretty much code like this :

which then i signal the ‘plastic bag’ node hence the area/body collide, then the goods will be hidden.

oh, here’s the code in the mainframe
Screenshot by Lightshot

extends Node
onready var test = get_node("Dialog").dialogue_trigger()
onready var dialogTrigger = get_node("Cashier").overPriceTrigger

.

func _ready():
get_node("GoodsMilk").hide()
get_node("GoodsMilk").finishMilk

get_node("GoodsRice").hide()
get_node("GoodsRice").finishRice

get_node("GoodsMeat").hide()
get_node("GoodsMeat").finishMeat

get_node("GoodsEgg").hide()
get_node("GoodsEgg").finishEgg

get_node("GoodsSaltedEgg").hide()
get_node("GoodsSaltedEgg").finishSaltedEgg

get_node("GoodsIceCream").hide()
get_node("GoodsIceCream").finishIceCream

get_node("GoodsEnergyDrink").hide()
get_node("GoodsEnergyDrink").finishEnergyDrink

get_node("GoodsMagazine").hide()
get_node("GoodsMagazine").finishMagazine

get_node("GoodsCondom").hide()
get_node("GoodsCondom").finishCondom

get_node("GoodsKidsToy").hide()
get_node("GoodsKidsToy").finishKidsToy	

set_physics_process(true)

func _process(delta):

if get_node("Button").goodsSpawn0 == 1 :
	get_node("GoodsMilk").show()
elif get_node("Button").goodsSpawn0 == 0 :
	get_node("GoodsMilk").hide()
if get_node("GoodsMilk").finishMilk:
	get_node("GoodsMilk").hide()
	
if get_node("Button").goodsSpawn1 == 1 :
	get_node("GoodsRice").show()
elif get_node("Button").goodsSpawn1 == 0 :
	get_node("GoodsRice").hide()
if get_node("GoodsRice").finishRice:
	get_node("GoodsRice").hide()
	
if get_node("Button").goodsSpawn2 == 1 :
	get_node("GoodsMeat").show()
elif get_node("Button").goodsSpawn2 == 0 :
	get_node("GoodsMeat").hide()
if get_node("GoodsMeat").finishMeat:
	get_node("GoodsMeat").hide()

if get_node("Button").goodsSpawn3 == 1 :
	get_node("GoodsEgg").show()
elif get_node("Button").goodsSpawn3 == 0 :
	get_node("GoodsEgg").hide()
if get_node("GoodsEgg").finishEgg:
	get_node("GoodsEgg").hide()
	
if get_node("Button").goodsSpawn4 == 1 :
	get_node("GoodsSaltedEgg").show()
elif get_node("Button").goodsSpawn4 == 0 :
	get_node("GoodsSaltedEgg").hide()
if get_node("GoodsSaltedEgg").finishSaltedEgg:
	get_node("GoodsSaltedEgg").hide()
	
if get_node("Button").goodsSpawn5 == 1 :
	get_node("GoodsIceCream").show()
elif get_node("Button").goodsSpawn5 == 0 :
	get_node("GoodsIceCream").hide()
if get_node("GoodsIceCream").finishIceCream:
	get_node("GoodsIceCream").hide()
	
if get_node("Button").goodsSpawn6 == 1 :
	get_node("GoodsEnergyDrink").show()
elif get_node("Button").goodsSpawn6 == 0 :
	get_node("GoodsEnergyDrink").hide()
if get_node("GoodsEnergyDrink").finishEnergyDrink:
	get_node("GoodsEnergyDrink").hide()
	
if get_node("Button").goodsSpawn7 == 1 :
	get_node("GoodsMagazine").show()
elif get_node("Button").goodsSpawn7 == 0 :
	get_node("GoodsMagazine").hide()
if get_node("GoodsMagazine").finishMagazine:
	get_node("GoodsMagazine").hide()
	
if get_node("Button").goodsSpawn8 == 1 :
	get_node("GoodsCondom").show()
elif get_node("Button").goodsSpawn8 == 0 :
	get_node("GoodsCondom").hide()
if get_node("GoodsCondom").finishCondom:
	get_node("GoodsCondom").hide()
	
if get_node("Button").goodsSpawn9 == 1 :
	get_node("GoodsKidsToy").show()
elif get_node("Button").goodsSpawn9 == 0 :
	get_node("GoodsKidsToy").hide()
if get_node("GoodsKidsToy").finishKidsToy:
	get_node("GoodsKidsToy").hide()

ColdCoffe | 2019-07-26 01:56

The images are not visible (Shows only: “Enter image description here” text)

KijeviGombooc | 2019-07-26 07:01

that’s weird, i changed it into a link instead,
thanks man.

ColdCoffe | 2019-07-26 08:58

Ok, so I think your problem is that when the area of the “PlasticBag” collides with another area, then the “PlasticBag” sends signal to all of your goods, calling the “_onPlasticBag_area_entered(area)” functionon all of them, so all of your goods have their finish property set to true. You could do a check whether the area collided is a NAMEGoods where NAME is the name of the given one. I don’t think that’s a nice way to do it though. At least check if that’s the problem, first (for example, put a print(GOODSNAME) into the signal method, and watch the output if all of their methods get called, im pretty sure they will be.)

On a kinda unrelated note: As far as I can tell, your goods all have the same structure of code, so you shouldn’t use a different script for each of them, but the same one. They all have same methods and stuff, only their properties are different (again, as far as I can tell). You can create a “Goods.gd” script and use that on all of them, and only change the export variable on the scripts, or you can look into resources.

KijeviGombooc | 2019-07-26 10:13

yes, they called all the goods function, is it because i use signal from the plastic bag?
i tried reverse it but it still do the same.

as for the

You can create a “Goods.gd” script and use that on all of them

do i have to put them goods on a single parent? or group? an example is really appreciated, since i just got here like 40 days?

thank you so much

ColdCoffe | 2019-07-27 08:21

What you could try is set a collision layer on both things: layer called “bin” for the bin and layer called “goods” for the goods. Then, yo u can set collision mask of the goods as bin, so you knwo when they collide with something, its gonna be the bin. That only works like this if u dont need them to collide with anything else though. Then you can set a signal on the goods for area_entered and since they only collide with the bin, you know that when they collide u gotta delete them.

Or, you can do another way, setting collision layers liek before, but setting mask only for the bin as “goods” (doesnt matter what u set goods to. Then, you can setup a script for the bin that destroys any object it collides with. You just coonect an _on_area_entered signal on the bin to itself (well, to the node on which bin script is on) then in that u can do area.queue_free() or however u wanna destroy the goods.

I prefer the latter, cause that way the goods dont need to knwo about the bin at all, only the bin’s collision mask has to be set up correctly.

As for the goods.gd script, u can attach a single script to multipel nodes. Just create the script, then select the node u want it to attavh to, and in the inspector on the bottom u can set the script.
Im sorry but i worked all weekend 12 hours a day and didnt rly have time to sit down to the computer, might have time today, but cant promise.

KijeviGombooc | 2019-07-29 06:14