1
\$\begingroup\$

I'm working on a game, and I'm trying to make an eating feature. I got the player's part down for the most part, but the food's script does not want to work it seems.

I've tried many different ways to make the food disappear once it's substance has reached 0 or less.

print "signal1" is the only one that doesn't activate at any time, and there are no errors.

The (top) main script is attached to the parent node of both the food and player scripts. "eating food"+"yum!" are printed out each bite until the substance reaches 0 or less, then it prints out "eating food"+"food eaten"+"yum!" for each bite after that.

The (mid) food script is attached to a kinematicbody2D, and the (bottom) player script is attached to another separate kinematicbody2D node.

Please let me know if there is a better way to do this?

main

extends KinematicBody2D
func _on_FoodPH_eaten():
    print("signal1")
    food.visible = not get_node("Food").visible
    food.queue_free()

food

func Eating():
    Substance -= 1
    print("eating food")
    if Substance <= 0:
        Eaten()

func Eaten():
    emit_signal("eaten")
    print("food eaten")

player

func _input(event):
    if event.is_action_pressed("Bite"):
        for body in $Player.get_overlapping_areas():
            if body.is_in_group("Food"):
                Food.Eating()
                emit_signal ("Eat")

func _on_Player_Eat():
    Hunger += 2
    print("yum!")
\$\endgroup\$
2
  • \$\begingroup\$ nevermind guys! I fixed it! \$\endgroup\$ Dec 25, 2022 at 19:49
  • 2
    \$\begingroup\$ But.... how!? 😅 Please consider adding an answer to your own question, for others encountering the same issue. \$\endgroup\$
    – Jeroen
    Mar 9 at 8:47

0

You must log in to answer this question.

Browse other questions tagged .