![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | MoxieTouch |
I’m looking for input on my code formatting and what I can do to improve readability. Below are a few of ones I’m not proud of.
# uses four step .ogg from the file directory
func _on_step_finished():
if rand_step < 4: rand_step += 1
else: rand_step = 1
var strang = "res://Assets/1_Audio/sfx/footsteps/footsteps/step" + str(rand_step) + ".ogg"
var step_audio : AudioStreamOGGVorbis = load(strang)
#print(step_audio, rand_step)
$Audio/step.stream = step_audio
Another function.
func spawn_fauna(var damage_fauna : int = 0):
# TODO: Code monster-spawning depending on the type of
# monster.
# TODO: Find code that automatically finds the scene
# in the file system, then use that instead of the
# string below
var monster = "f_" + mon_grappled
var prelim = "res://Entities/Fauna/f_subtypes/"
var fauna_loc = prelim + monster + "/" + monster + ".tscn"
var fauna = load(fauna_loc)
var fauna_inst = fauna.instance()
fauna_inst._func_ready_take_damage = damage_fauna
spawn_inst(fauna_inst)
Should I also batch my variables at the top of the script like below? Or just put variables near functions that need them?
export (int) var acceleration = 50
export (float) var slowdown = .20
export (float) var afterglow_time = 0
export (Array) var player_states_i_can_saucy = []
onready var Obj
onready var enterDetect = get_node("detectBodies/enterDetect")
onready var exitDetect = get_node("detectBodies/exitDetect")
onready var attackRange = get_node("detectBodies/attackRange")
onready var world = get_parent()
var afterglow : bool = false
var _func_ready_take_damage : int = 0
var player_near_chasing_range : bool = false
var hurt_in_day = false
var is_alive = true
var active_attack : bool = false