Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dudedude123 |
I’m setting up the player system similar to Tekken 7 where the player can choose sides. I want to transfer this info
PlayerSelectScript.gd
extends Sprite
# Object Array
var characters = [] # Array to store all the characters the player can select
# Integer
var currentSelected = 0 # Spot of the cursor within the characters[]
var currentColumnSpot = 0 # Spot of the cursor based on the column
var currentRowSpot = 0 # Spot of the cursor based on the row
# Exports
export (Texture) var player1Text # Cursor Texture for when Player 1 is making a decision
export (Texture) var player2Text # Cursor Texture for when Player 2 is making a decision
func _ready():
# Get all of the characters stored within the group "Characters" and place them in the Array characters
for nameOfBoxer in get_tree().get_nodes_in_group("characters"):
boxers.append(nameOfcharacter)
# print(characters)
texture = player1Text
CharacterSelectionManager.characterOne = $Spatial
CharacterSelectionManager.characterTwo = $Spatial2
# This whole _process(delta) function is used to allow scrolling through all the characters
func _process(delta):
if(Global.playerOne = CharacterSelectionManager.characterOne):
if(Input.is_action_just_pressed("ui_up") && current_character>1):
#calc the angle to rotate
target_rotation = target_rotation + Vector3(0,90,0)
current_character-=1
#if you press right and is the last character to the right...
if(Input.is_action_just_pressed("ui_down") && current_character<max_characters):
#calc the angle to rotate
target_rotation = target_rotation - Vector3(0,90,0)
current_character+=1
if(Input.is_action_just_pressed("ui_right")):
Global.playerOne = null
if(Global.playerOne = CharacterSelectionManager.characterTwo):
if(Input.is_action_just_pressed("ui_up") && current_character>1):
#calc the angle to rotate
target_rotation = target_rotation + Vector3(0,90,0)
current_character-=1
#if you press right and is the last character to the right...
if(Input.is_action_just_pressed("ui_down") && current_character<max_characters):
#calc the angle to rotate
target_rotation = target_rotation - Vector3(0,90,0)
current_character+=1
if(Input.is_action_just_pressed("ui_left")):
Global.playerOne = null
if(Global.playerOne = null):
if(Input.is_action_just_pressed("ui_right")):
Global.playerOne = CharacterSelectionManager.currentSide(CharacterSelectionManager.characterTwo)
if(Input.is_action_just_pressed("ui_left")):
Global.playerOne = CharacterSelectionManager.currentSide(CharacterSelectionManager.characterOne)
if(Global.playerTwo = null):
if(Input.is_action_just_pressed("ui_right")):
Global.playerTwo = CharacterSelectionManager.currentSide(CharacterSelectionManager.characterTwo)
if(Input.is_action_just_pressed("ui_left")):
Global.playerTwo = CharacterSelectionManager.currentSide(CharacterSelectionManager.characterOne)
if(Global.playerTwo = CharacterSelectionManager.characterOne):
if(Input.is_action_just_pressed("ui_up") && current_character>1):
#calc the angle to rotate
target_rotation = target_rotation + Vector3(0,90,0)
current_character-=1
#if you press right and is the last character to the right...
if(Input.is_action_just_pressed("ui_down") && current_character<max_characters):
#calc the angle to rotate
target_rotation = target_rotation - Vector3(0,90,0)
current_character+=1
if(Input.is_action_just_pressed("ui_right")):
Global.playerTwo = null
if(Global.playerTwo = CharacterSelectionManager.characterTwo):
if(Input.is_action_just_pressed("ui_up") && current_character>1):
#calc the angle to rotate
target_rotation = target_rotation + Vector3(0,90,0)
current_character-=1
#if you press right and is the last character to the right...
if(Input.is_action_just_pressed("ui_down") && current_character<max_characters):
#calc the angle to rotate
target_rotation = target_rotation - Vector3(0,90,0)
current_character+=1
if(Input.is_action_just_pressed("ui_left")):
Global.playerTwo = null
# If a selection is made send it to the Signleton CharacterSelectionManager.gd to store that value
if(Input.is_action_just_pressed("ui_accept")):
# print(characters[currentSelected].name)
# CharacterSelectionManager.player1Character = characters[currentSelected].name
CharacterSelectionManager.currentSide selected
CharacterSelectionManager.characterOne = CharacterSelectionManager.selectableCharacters[characters[currentSelected].name]
CharacterSelectionManager.characterTwo = CharacterSelectionManager.selectableCharacters[characters[currentSelected].name]
CharacterSelectionManager.characterTwoSelected = currentSelected
CharacterSelectionManager.characterOneSelected = currentSelected
get_tree().change_scene("res://Assets/Scenes/Game.tscn")
To this
GameScript.gd
extends Node2D
onready var characterOnepos = $Player1Pos
onready var characterTwopos = $Player2Pos
func _ready():
# print(CharacterSelectionManager.player1Character)
SpawnChosenCharacters()
# At the start of the game the chosen characters need to be spawned in and also receive an offset to eachother
func SpawnChosenCharacters():
CharacterSelectionManager.characterOne = CharacterSelectionManager.characterOne.instance() # What character player 1 has chosen to be
CharacterSelectionManager.characterOne.set_name(str(get_tree().get_network_unique_id()))
CharacterSelectionManager.characterOne.set_network_master(get_tree().get_network_unique_id())
CharacterSelectionManager.characterOne.global_transform = characterOnepos.global_transform
add_child(CharacterSelectionManager.characterOne)
if(CharacterSelectionManager.characterOne = null):
CharacterSelectionManager.characterOne.set_script(CharacterSelectionManager.aiScript) # Set the right script on to the AI (opponent)
else:
CharacterSelectionManager.characterOne.set_script(CharacterSelectionManager.playerScript) # Set the right script on to the player
call_deferred("add_child", characterOne)
CharacterSelectionManager.characterTwo = CharacterSelectionManager.characterTwo.instance() # What character player 2 has chosen to be
CharacterSelectionManager.characterTwo.set_name(str(Globals.player2id))
CharacterSelectionManager.characterTwo.set_network_master(Globals.player2id)
CharacterSelectionManager.characterTwo.global_transform = hostBoxerpos.global_transform
add_child(CharacterSelectionManager.characterTwo)
if(CharacterSelectionManager.characterTwo = null):
CharacterSelectionManager.characterTwo.set_script(CharacterSelectionManager.aiScript) # Set the right script on to the AI (opponent)
else:
CharacterSelectionManager.characterTwo.set_script(CharacterSelectionManager.playerScript) # Set the right script on to the player
call_deferred("add_child", characterTwo)
I keep having unexpected assign error on this code
if(CharacterSelectionManager.characterOne = null):
CharacterSelectionManager.characterOne.set_script(CharacterSelectionManager.aiScript) # Set the right script on to the AI (opponent)
else:
CharacterSelectionManager.characterOne.set_script(CharacterSelectionManager.playerScript) # Set the right script on to the player