godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.95k stars 20.17k forks source link

Internal script error Opcode : 101 #95908

Closed darksignal7 closed 15 hours ago

darksignal7 commented 3 weeks ago

Tested versions

Godot 4.2.2 -stable

System information

Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated Radeon RX 580 Series (Advanced Micro Devices, Inc.; 31.0.21912.14) - AMD Ryzen 5 3600 6-Core Processor (12 Threads)

Issue description

Adsız

Full code of the script if needed:

extends CharacterBody3D

@onready var player_raycast = $player_raycast
@onready var player = $"../player"

@onready var anim = $anim
var health = 0
var max_health = 100
var foot_health = 100
var died = false
var last_pos = 0
var frst_health = null

@onready var gethurt_1 = $sounds/gethurt/gethurt1
@onready var gethurt_2 = $sounds/gethurt/gethurt2
@onready var gethurt_3 = $sounds/gethurt/gethurt3
@onready var attack_1 = $sounds/attack/attack1
@onready var attack_2 = $sounds/attack/attack2
@onready var trigger_1 = $sounds/trigger/trigger1
@onready var trigger_2 = $sounds/trigger/trigger2
@onready var trigger_3 = $sounds/trigger/trigger3
@onready var armor = $zombie_visual/Armature/Skeleton3D/body_bone/armor
@onready var hat = $zombie_visual/Armature/Skeleton3D/head_bone/hat
var random = -1
var did_trigger = false
var dt_tmr = 0
var grav = 1
var armor_amount = 0

@export var canrun = false
var spd = 3
var state = "random"
#CAN BE:
# waiting
# random
var random_finished = true
var random_rot = 0
# walking
# running
# crawl-waiting
# crawling
# discomfort

func _ready():

    anim.play("Zombie-Base/Idle-2")
    if state == "random":
        _random()

    armor_amount = randi_range(0,3)
    if armor_amount == 0:
        armor.queue_free()
        hat.queue_free()
        max_health = 100
    elif armor_amount == 1:
        hat.queue_free()
        max_health = 175
    elif armor_amount == 2:
        armor.queue_free()
        max_health = 150
    else:
        max_health = 200        
    health = max_health
    frst_health = health

func _process(delta):
    if !is_on_floor():
        velocity.y = -grav

    player_raycast.look_at(player.global_position)
    if is_instance_valid(player_raycast.get_collider()):
        if player_raycast.get_collider().name == "player":
            if !canrun:
                state = "walking"
                player._debug("Nearest Zombie State : Walking")
                _play_random("trigger")
            else:
                state = "running"
                player._debug("Nearest Zombie State : Running")
                _play_random("trigger")
        else:
            state = "random"

            #did_trigger = false

    if health < frst_health/2 and !canrun:
        canrun = true

#region Dead
    if health <= 0:
        state = "dead"
    if state == "dead":
        position.y = lerp(position.y , float(last_pos) , .1)
#endregion

#region Walking
    if state == "walking":
        if global_position.distance_to(player.global_position) < 1.5:
            velocity = Vector3.ZERO
            if anim.current_animation != "Zombie-Base/Attack":
                anim.play("Zombie-Base/Attack")
                anim.seek(0.8)
        else:
            if anim.current_animation != "Zombie-Base/Attack":
                anim.play("Zombie-Walk/Walk")
            look_at(Vector3(
                player.position.x,
                position.y,
                player.position.z
            ))
            velocity = -global_transform.basis.z / 3
#endregion

#region Running
    if state == "running":
        if global_position.distance_to(player.global_position) < 1.7:
            velocity = Vector3.ZERO
            if anim.current_animation != "Zombie-Base/Attack":
                anim.play("Zombie-Base/Attack")
                anim.seek(0.8)
        else:
            if anim.current_animation != "Zombie-Base/Attack":
                anim.play("Zombie-Base/Run")
            look_at(Vector3(
                player.position.x,
                position.y,
                player.position.z
            ))
            velocity = -global_transform.basis.z / 1.2
#endregion

    if state == "dead":
        velocity = Vector3.ZERO
    elif did_trigger:
        dt_tmr += 1
        if dt_tmr > 750:
            did_trigger = false
            dt_tmr = 0      
    move_and_slide()

func _random():
    if state == "random":
        await get_tree().create_timer(2.5).timeout
        anim.play("Zombie-Walk/Walk")
        velocity = -global_transform.basis.z / 3
        await get_tree().create_timer(randi_range(5,15)).timeout
        velocity = Vector3.ZERO
        _random_finished()
        anim.play("Zombie-Base/Idle")

func _random_finished():
    rotation_degrees.y = randi_range(0,360)
    _random()

func head_hit(damage : int):
    _play_random("gethurt")
    if state != "dead":
        if died == false:
            health -= damage
            if health <= 0:
                var chance = randi_range(1,2)
                if chance == 1:
                    anim.play("Zombie-Base/Die")
                    _died()
                else:
                    anim.play("Zombie-Base/Die-2")
                    _died()
            else:
                anim.play("Zombie-Base/Get-Hit")
                anim.seek(.3)

func body_hit(damage : int):
    _play_random("gethurt")
    health -= damage / 2

func foot_hit(damage : int):
    _play_random("gethurt")
    health -= damage / 3

func _died():
    last_pos = position.y - .22

func _play_random(sound : String):
    if sound == "gethurt":
        random = randi_range(1,3)
        if random == 1:
            gethurt_1.play()
        elif random == 2:
            gethurt_2.play()
        elif random == 3:
            gethurt_3.play()
    elif sound == "trigger":
        if !did_trigger:
            random = randi_range(1,3)
            did_trigger = true
            if random == 1:
                trigger_1.play()
            elif random == 2:
                trigger_2.play()
            elif random == 3:
                trigger_3.play()

Steps to reproduce

I was making the game stop-resume while using the profiler in Godot, at this time it gave such an error.

Minimal reproduction project (MRP)

I dont think i need to upload my project here for this bug.

AThousandShips commented 3 weeks ago

Please add this code to a new empty project and see if the error still occurs, if it does please upload that project as an MRP, if it doesn't then this needs more details and steps and it'll be very hard to identify what's wrong with so limited information

darksignal7 commented 3 weeks ago

Please add this code to a new empty project and see if the error still occurs, if it does please upload that project as an MRP, if it doesn't then this needs more details and steps and it'll be very hard to identify what's wrong with so limited information

  • A small Godot project which reproduces the issue, with no unnecessary files included. Be sure to not include the .godot folder in the archive (but keep project.godot).
  • Having an MRP is very important for contributors to be able to reproduce the bug in the same way that you are experiencing it. When testing a potential fix for the issue, contributors will use the MRP to validate that the fix is working as intended.
  • Drag and drop a ZIP archive to upload it (max 10 MB). Do not select another field until the project is done uploading.
  • Note for C# users: If your issue is not C#-specific, please upload a minimal reproduction project written in GDScript. This will make it easier for contributors to reproduce the issue locally as not everyone has a .NET setup available.

Although the error code runs continuously during the game, it only appeared once when stopping and restarting the game while using the profiler. I think the problem may have occurred because I stopped the game during the timeout line.

AThousandShips commented 3 weeks ago

That sounds very likely, some form of memory or reference issue

Though you are doing some pretty risky code by entering an infinite recursion by calling _random -> _random_finished -> _random, that seems like a thing you shouldn't be doing

AThousandShips commented 15 hours ago

Closing as no MRP has been uploaded, if one is this can be reopened