#i am trying to make a tic tac toe game
1 messages · Page 1 of 1 (latest)
yeah i do have two network variables
current turn and hostSide
current turn stores whose turn it currently is
and hostSide stores the side that host initiaally picked
i have handled it somewhat like this :
https://pastebin.com/zqwA7P3U
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i know its messy but i could make it work like this only
this is the project:
https://github.com/RandomMaths/tic-tac-toe_Android
i shouldnt be calling the Server RPC to update on host side rigth?
as when i call the client side it updates both the sides
You can use either RPC or network variable for that but you would not need to use both, just have ge host set the network vsribale and it will automatically sync to the client
Yeah but then I need to change the list when the Client clicks a button
And as only the server can make a change in that i need to call that from the client side
i am currently calling this from the cleint side
[ServerRpc (RequireOwnership = false)]
private void UpdateButtonsServerRpc(int grid)
{
//cells[grid] = 1;
buttonList[grid].transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = currentTurn.Value.ToString();
integerList[grid] = 1;
for (int i = 0; i < integerList.Count; i++)
{
if (integerList[i] == 0)
{
buttonList[i].interactable = true;
}
else
{
buttonList[i].interactable = false;
}
}
if (playerX.panel.color == activePlayerColor.panelColor)
{
SetPlayerColor(playerO, playerX);
}
else if (playerO.panel.color == activePlayerColor.panelColor)
{
SetPlayerColor(playerX, playerO);
}
buttonList[grid].interactable = false;
UpdateButtonsClientRpc(grid);
}
i was able to get the turns right
it is almost complete
but how can i make the client and host disconnect without giving any error?
when i go back to main menu and then again to online play mode it doesnt load the prefab and says (Object reference is not set to an instance of an object)
If the main menu is a scene with the network manager already in it, then when you go back to it, you will have duplicate network managers. So you will either need to destroy the one already there or just remove the network manager from the main menu scene. Most folks will have a bootstrap scene that sets up all the managers before the main menu scene. That way you can go back to the menu with no issues
I have the Network Manager in the game scene
How about I just destroy the Network Manager when I click to go back to main menu?
That should be fine too
ok ill try that
which time zone are you in btw?
i dont think our time zones coincide
thats why our replies are far apart
and then school take almost half a day too
-6 UTC. Central time in the US
Oh that explains UTC+5:30 Central time in India
yeah that worked
now one last step is left before its completion
i am trying out relay services for the first time
the code i am using is like this :
public async void StartHost()
{
try
{
Allocation allocation = await RelayService.Instance.CreateAllocationAsync(1);
joinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
RelayServerData relayServerData = new RelayServerData(allocation, "dtls");
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
NetworkManager.Singleton.StartHost();
ActivatePlaceholderPanel(true);//This is a game object which just displays the current join code
}catch (RelayServiceException e)
{
Debug.Log(e.ToString());
}
}
public async void JoinGame()
{
try
{
JoinAllocation joinAllocation = await RelayService.Instance.JoinAllocationAsync(codeArea.transform.GetChild(0).GetChild(2).GetComponent<TextMeshProUGUI>().text);
RelayServerData relayServerData = new RelayServerData(joinAllocation, "dtls");
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
NetworkManager.Singleton.StartClient();
} catch (RelayServiceException e)
{
Debug.Log(e.ToString());
}
}
and for disconnecting i am doing the following:
public void Disconnect()
{
if(NetworkManager.Singleton.IsConnectedClient)
NetworkManager.Singleton.Shutdown();
Destroy(NetworkManager);
}
i just want to know wether i have to do soemthing else too
like when i am acclocating apce on relay do i need to erase it too when the game is done
and in disconnect fucntion do i need to turn off relay or signout clients
i did what i could from what i had learnt
No, shutdown() is all you need to do there
ok then ill remove the Destroying function
i tried to connect from the client vai relay
its giving me this error :
Bad Request : invalid requiest schema or decoding failure
The client would need to manually enter the code. It would not get it from the host
yeah i entered the code
i have a text box which shows up
and it can read the code from their
at first i thought it wasnt able to get the code from the input field
but i tried to debug it and its value updated
i read a few threads
i think it might be either due to the wifi
it shows that tmpro adds an empty space at the end when value is taken from it
i have tried to cut it down
its currently building
it worked!!!
the problem was the empty space only
well this was my first project that i took seriously for once
and you were of great help in many errors that i didnt understand at all
so thanks a lot for all your help and all the time that you gave
i am really greatful
have you ever heard of ultimate tic tac toe?
Ultimate Tic Tac Toe, also known as Nine Board Tic Tac Toe, is an interesting variation on the classic game. The board is composed of a 3x3 grid of Big Squares. Inside of each Big Square is another 3x3 grid, so there are 9 Small Squares inside each Big Square. The position you play in a Small Square then determines which Big Square your opponent...
it is possible to make nested netowork lists?
No that will cause errors. It would be easier to just flatten the double list
OK I'll do that then
i want the canvas to have a render mode of ScreenSpace - Overlay
but that requires a camera componenet
as it is a netowrk prefab i am not able to enter the camera componenet which i am using for other canvases as the camera is a component in the heiarchy
i tried making it a prefab, i was able to enter is as a component but it still isnt displying anythign when i join it to the game
The canvas should not be a network object. that will cause some weird scaling issues. But in any case you will need a script to assign the camera
i already have been using that since the very begininng
whole game works on ui componenets
i was spawning the panels and buttons and all but they needed a panel a canvas to display and werent being dispalyed so i used a canvas a network compoenent
though it isnt showing any scaling issues
should i use a camera as a prefab or a gameobject in the scene?
I will usually just keep them as regular objects in the scene. Then in the objects that need them, in their OnNetworkSpawn() use GameObject.Find() to grab what they need
ohh
so should i remove the canvas object from being a network object?