#Make me feel bad about the way I wrote my script (and maybe some constructive criticism too!)

12 messages · Page 1 of 1 (latest)

sick sonnet
#
class_name GameControlClass
extends Control

@onready var user_input = $UserInput
@onready var output_window = $OutputPanel/Output
var is_tween_called: bool = false
var text_grab: String = ""
var color_tween: Tween
var text_tween: Tween
var particle_tween: Tween
const introduction_const = preload("res://Assets/Scripts/StoryResourceScript.gd")
var is_working_on: bool

func _ready():
    # Configuration Portion
    output_window.bbcode_enabled = true
    output_window.scroll_following = true
    # Local Variables
    var introduction_script = introduction_const.new()
    # Logic
    user_input.editable = false
    text_graduality(introduction_script.introduction_text)

    
    
func _on_game_tick_timeout():
    await_call()

func await_call():
    if color_tween:
        color_tween.kill()
    if text_tween:
        text_tween.kill()
    if is_tween_called == true:
        if text_grab == "":
            pass
        else:
            user_input.editable = false
            text_graduality(text_grab)
        is_tween_called = false
    if is_working_on == true:
        user_input.editable = false
    else:
        pass
    
func text_graduality(new_text):
    is_working_on == true
    var text = new_text.split()
    var point: int = text.size()
    var end_point: int = 0
    while point > end_point:
        for word in text:
            for char in word:
                output_window.append_text(char)
                await wait_for_seconds(0.01)
                point -= 1
                print("chars left: "+ str(point))
    output_window.newline()
    user_input.editable = true
    is_working_on == false
    #
    # Debug Stuff
    #
    print("end_size is: " + str(end_point))
    
func text_popout_effect(new_text):
    pass #next thing to do

func wait_for_seconds(duration):
    var timer = Timer.new()
    timer.wait_time = duration
    timer.one_shot = true
    add_child(timer)
    timer.start()
    await timer.timeout
    timer.queue_free()


func _on_user_input_text_submitted(new_text):
    is_tween_called = true
    text_grab = new_text
    user_input.clear()

If I can provide any insight into anything please let me know. This is for a text based adventure game.

#

Please also note that this is not completed, I am more asking for help with the portion that is written.

winged mist
agile frost
#

Could shorten your wait_for_seconds() function probably - overall it's good though

func wait_for_seconds(duration):
    await get_tree().create_timer(duration).timeout
bright solar
#

is_working_on == true doesn’t look like it has any effect

#

same with the == false at the end

#

in text_graduality()

agile frost
#

is_working_on is checked in await_call(), it seems it's being set in preparation for that, to make user input editable or not

bright solar
#

yes but that line is comparing is_working_on to true

#

not setting it to true

#

and the result is just going to nowhere

sick sonnet
#

@bright solar ah thanks! I actually meant to set it, that's an error for sure.