I'm having a problem with making a start screen and adding a menu to it after when the user presses start.
The problem is that it seems to skip the menu altogether and just starts the game, I checked the code, and everything seems to be in order, so I'm assuming that it's just that the button recognition is way too sensitive, even though the script I'm using allows for a check if the key is pressed then released.
Here's my code:
#Start Screen Code
extends Spatial
export(NodePath) var animationNode
export(NodePath) var mainMenu
export(String, FILE) var nextScene
var input_states = preload("res://Scripts/input_states.gd")
var btn_start = input_states.new("ui_accept")
func _process(delta):
if btn_start.check() == 1:
if get_node(animationNode).get_current_animation() == "Start_Screen":
get_node(mainMenu).activate(delta)
changeAnimation("Menu")
elif !get_node(mainMenu).isActiveMenu():
changeAnimation("Start_Screen")
func changeAnimation(value):
get_node(animationNode).set_current_animation(value)
get_node(animationNode).play(value)
__________
#Menu Script
extends Control
# member variables here, example:
# var a=2
# var b="textvar"
var input_states = preload("res://Scripts/input_states.gd")
export(int, "Main", "Pause") var menuType
export(Array) var menuItems
export(NodePath) var higherUpMenu
export(NodePath) var globalScript
var currentlySelected = 0
export(bool) var activeMenu = false
var btnUp = input_states.new("ui_up")
var btnDown = input_states.new("ui_down")
var btnSelect = input_states.new("ui_accept")
func _ready():
# Called every time the node is added to the scene.
# Initialization here
set_fixed_process(true)
pass
func _fixed_process(delta):
if activeMenu:
if menuType == 1:
if get_tree().is_paused():
show()
if menuItems.size() > 1:
menuNavigation()
else:
show()
if menuItems.size() > 1:
menuNavigation()
else:
hide()
#This makes it so that when the user pressed up or down, the menu items will scroll accordingly
#If they press select, then the game will do the menu's action
func menuNavigation():
if btnDown.check() == 1:
clearAll()
if currentlySelected < menuItems.size() - 1:
currentlySelected += 1
else:
currentlySelected = 0
get_node(menuItems[currentlySelected]).setCurrentlySelected(true)
elif btnUp.check() == 1:
clearAll()
if currentlySelected > 0:
currentlySelected -= 1
else:
currentlySelected = menuItems.size() -1
get_node(menuItems[currentlySelected]).setCurrentlySelected(true)
if btnSelect.check() == 1:
get_node(menuItems[currentlySelected]).execute()
#This function is to clear all elements, this is used if the user uses the mouse rather than the keys
#to hover over a menu option.
func clearAll():
for item in menuItems:
get_node(item).setCurrentlySelected(false)
#This function is for when the use decides to exit, for example, in a pause menu, this will unpause the game
func exit_menu():
if (menuType == 1):
get_tree().set_pause(false)
setAsActiveMenu(false)
func activate(delta):
var timer = 0
while(timer < 0.5):
timer += delta
setAsActiveMenu(true)
__________
#Menu item Script
extends Container
export(int, "Scene Change", "Value change", "Menu Changer", "Exit Menu") var menuItemType
export(Array) var arguments
export(NodePath) var animationPlayer
export(String, FILE) var fileSelectPlaceholder
var timer = 0
var cooler = 1
var currentlySelected = false
func _ready():
# Called every time the node is added to the scene.
# Initialization here
pass
#This is set this as whether or not it is the currently selected item in the menu
func setCurrentlySelected(value):
currentlySelected = value
if currentlySelected == true:
get_node(animationPlayer).play("Selected")
else:
get_node(animationPlayer).play("Idle")
func _on_Container_mouse_enter():
get_node(animationPlayer).play("Selected")
setCurrentlySelected(true)
func _on_Container_mouse_exit():
get_node(animationPlayer).play("Idle")
setCurrentlySelected(false)
func _input_event(event):
if (event.type == InputEvent.MOUSE_BUTTON):
execute()
# This executes the menu item's command, which depends on which type it is, it will change the scene
# if it's the scene type, it will change a value if it's a value changer, and it will change the menu
# if it's a menu changer, it can also exit the current menu.
func execute():
if menuItemType == 0:
get_tree().set_pause(false)
get_tree().change_scene(arguments[0])
elif menuItemType == 3:
get_node(arguments[0]).exit_menu()
What am I doing wrong?