Sending variables...

Hello,
i am testing right now Bolt and Forge Networking.

And at booth solutions am i on the point where i have to send a variable over the network, but i dont get it how to do it.

At Forge it just dont work with [NetSync] so i am searching something like that.

What i want to do:
Player creates Server -> int playerID = 0
Player spawns at spawn 1 (since theplayerid is 0)
Player sets playerID to 1

Player2 Joins the server
Player2 get the playerID (Which should be 1 now)
Player2 spawns at spawn 2 (since the playerID is 1)

Which would look in code like that:

public Transform spawn1;
publci Transform spawn2;

if(playerID == 0)
{
      Instantiate....... spawn1.position, quaternion bla blalba
}else
{
    same stuff as obove but with the spawn2.position
}
Sorry for my bad english, im from switzerland and i hope someone can help me with this issue

Comments

  • Have you tried to follow the tutorial i.e. Bolt 101?
  • Yes but i dont know if i just can do the same like with the color stuff (just with a integer)
    Since it wasnt working like i did
  • Add an integer to a state and set it. It is then replicated to clients.
  • Wizzard said:

    Add an integer to a state and set it. It is then replicated to clients.

    I tryed it now like that:
    public Transform spawn1; public Transform spawn2; public override void Attached() { spawn1 = GameObject.Find ("/Spawnpoint").GetComponent<Transform>(); spawn2 = GameObject.Find ("/Spawnpoint (1)").GetComponent<Transform> (); switch(state.PlayerID) { case 0: transform.position = spawn1.position; break; case 1: transform.position = spawn2.position; break; } state.Transform.SetTransforms (transform); state.PlayerID++; }

    Well its not working...
    Both players spawn at spawn1 and one player has the ID 1 and the second player the ID 2
  • I dont find an edit button so i gonna have to write here:

    I tested now a bit and the PlayerID number, which is a state(integer) at the player stuff
    doesnt get replicated, even when i set its replication mode to "Everyone"
  • Some things to keep in mind
    (1) I'm not sure if states are replicated by the time Attached() is ran - you probably have to wait a bit
    (2) Only the owner of the entity can edit the state and have it replicate (proxies and controllers cannot)
  • well i tryed now exact 8 ways to do it... nothing works...

    Most times i get this error
    BoltException: You can't access any Bolt specific methods or properties on an entity which is detached

    Can't someone make a example code ?
    Im pretty much lost at this stuff :(
  • Did you take a look at the tutorial included with Bolt? It is a good example
  • Make sure you use BoltNetwork.Instantiate to instantiate a player prefab with a BoltEntity component
  • stanchion said:

    Did you take a look at the tutorial included with Bolt? It is a good example

    Yes, or i think yes ? (The tutorial on the website or is there anything more)
    Wizzard said:

    Make sure you use BoltNetwork.Instantiate to instantiate a player prefab with a BoltEntity component

    The instatiate stuff works but the synced variable (SpawnID / PlayerID) doesnt sync at all clients to the same number or i cant access it to check on what value it is at the moment (like in a if statement)
  • There is an example project included when you download Bolt. You are probably trying to modify the state property on non owners so it is not changing.
  • SynterGames
    edited September 2015
    Found it but i made it the same way i guess
    • Created empty Gameobject
    • Renamed it to "PlayerSpawner"
    • Created a C# script and named it makePlayer.cs
    • Added a Bolt Entity component to the "PlayerSpawner"
    • Created a new State named PlayerSpawning
    • Created a property named spawnID (Integer)
    • Compiled assembly
    C# Script content 1st version: (The boltentity part could be different since im writing this from my laptop (No Unity on here :( )
    using UnityEngine; using System.Collections; public class NetworkCallbacks : Bolt.GlobalEventListener { BoltEntity entity; public Transform spawn1; public Transform spawn2; void Awake() { entity = GetComponent<BoltEntitiy>(); } public override void SceneLoadLocalDone(string map) { if(entity.state.spawnID == 0) { BoltNetwork.Instantiate(BoltPrefabs.Cube, spawn1.position, Quaternion.identity); entity.state.spawnID++; }else { BoltNetwork.Instantiate(BoltPrefabs.Cube, spawn2.position, Quaternion.identity); } } }


    Version 2: (i dont know if this was working since the Player never got spawned)
    using UnityEngine; using System.Collections; public class NetworkCallbacks : Bolt.EntityBehaviour<IPlayerSpawner> { public Transform spawn1; public Transform spawn2; void SceneLoadLocalDone(string map) { if(state.spawnID == 0) { BoltNetwork.Instantiate(BoltPrefabs.Cube, spawn1.position, Quaternion.identity); state.spawnID++; }else { BoltNetwork.Instantiate(BoltPrefabs.Cube, spawn2.position, Quaternion.identity); } } }


    I hope everything was written correct (I had no errors in the original file)
    Again i wrote everything by my self without debug stuff or something else since im at home and not in my office.

    Hope someone can tell me what ive done wrong
  • Mark as [SOLVED]

    Yesterday i was looking South Park... And i got Enlightened
    To be the owner - someone has to Instantiate it... So the Server is always the Main owner logically, since hes the server / host so i managed it now like this:

    NetworkCallbacks.cs (Instantiates my GameManager - Owner = Host)
    http://pastebin.com/41kGHzcP

    COOPGameManager.cs(Controlling game process)
    http://pastebin.com/mJ5XP0Zz

    (For person which are too lazy too look at the pastes)
    NetworkCallbacks - instantiates the GameManger (Only for the host)
    The GameManager instantiates then the player (at the start function) and sets the value to 1 (only host)
    So if a second player joins he will receive the GameManager is instantiated and starts the script of it (start function e.t.c.)

    With the spawnID == 1 he will spawn at the second point :dizzy:

    I dont know if it would be easyer or a shorter way yet, but it works and im happy with it :smiley:

    So this here is [SOLVED] for me (Dont know if i can set it to Solved)