Search Unity

Make Change to variable base on which player move - ChilliConnect

Discussion in 'Scripting' started by wraith1821, Jul 27, 2018.

  1. wraith1821

    wraith1821

    Joined:
    Nov 26, 2017
    Posts:
    30
    I'm making a turn based board game, using chilliconnect for multiplayer.

    The realtime tic-tac-toe project is what I'm researching at this time. If I want to record a value to an integer variable for Player X after their move and then player O after their move. How do you achieve this using chilliconnect's code. I feel like I'm overlooking something or losing my mind.

    Here is a bit of the code from GridSpace.cs:
    Code (CSharp):
    1.  
    2. public void SetSpace()
    3.     {
    4.         buttonText1.text = gameController.GetPlayerSide();
    5.         buttonText2.GetComponent< Text > ().enabled = false;
    6.         gameController.lastPlayedSquareValue = squareValue;
    7.         button.interactable = false;
    8.         gameController.EndTurn();
    9.     }
    10.  
    This script is attached to the button.

    lastPlayedSquareValue I want to be lastPlayedSquareValueX or lastPlayedSquareValueO respectively.
    squareValue is a preset value assigned to each square on the board at game start.

    GetPlayerSide() in GameController.cs is GetPlayerSide(string player)


    Ive tried to set the variable values in SetSpace() and EndTurn(). Also added a function for onClick. I think my issue is I don't know how I should be defining the player within a conditional statement as every attempt prevents me from setting pieces on the board.

    Thanks for any help