Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dellan_X · Apr 20, 2012 at 02:30 AM · networkvariablestringstransfer

Strings through a network?

hi I am making a RTS style game where you build armies/bases and attack your friends/enemies army/base(I was making this on DellanX, but the password for the login was mest up, so I created a new account). I am having trouble with sending my variables to the network. In this case I am sending each players name, faction name, color, and alliance to the network. I need all players to be able to see eachothers name/army/faction, but I cant seem to figure it out. I know very little about RPC, and I dont have enough knowledge to use it to solve this problem.

EDIT:

in case you didn't see the comment below

I attempted to figure out RPC, but am having problems. I am Using arrays to store players, but when I connect to my server my variables arent changed. I am using code like:

 public ArrayList PlayerName = ArrayList public string MyName = ""; //Script for GUI here
 
 void OnServerInitialized(){
 
 MyName = "BLUE";//For identification
 
 networkView.RPC("SetServerInfo",RPCMode.All);
 
 }
 
 void OnConnectedToServer(){
 
 MyName = "RED";//For identification
 
 networkView.RPC("SetServerInfo",RPCMode.All);
 
 }
 
 [RPC]
 
 void SetServerInfo(){
 
 PlayerName.Add(MyName);
 Debug.Log(PlayerName[0])//Show What the first name stored is
 
 }

When I run my program as server I get in my log:

BLUE

When I run my program as client I get:

RED

What am I doing wrong? and what do I need to do to fix it???

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Apr 20, 2012 at 02:33 AM 0
Share

RPC can send strings, no trouble. What's the issue? It can also send byte arrays, which is as useful as it is undocumented...

avatar image Dellan_X · Apr 20, 2012 at 02:44 AM 0
Share

I dont know how to use RPC.

avatar image Dellan_X · Apr 20, 2012 at 06:59 AM 0
Share

I attempted to figure out RPC, but am having problems. I am Using arrays to store players, but when I connect to my server my variables arent changed. I am using code like:

public ArrayList PlayerName = ArrayList public string $$anonymous$$yName = ""; //Script for GUI here

void OnServerInitialized(){

$$anonymous$$yName = "BLUE";//For identification

networkView.RPC("SetServerInfo",RPC$$anonymous$$ode.All);

}

void OnConnectedToServer(){

$$anonymous$$yName = "RED";//For identification

networkView.RPC("SetServerInfo",RPC$$anonymous$$ode.All);

}

[RPC]

void SetServerInfo(){

PlayerName.Add($$anonymous$$yName); Debug.Log(PlayerName[0])//Show What the first name stored is

}

When I run my program as server I get in my log:

BLUE

When I run my program as client I get:

RED

What am I doing wrong? and what do I need to do to fix it???

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dellan_X · Apr 20, 2012 at 04:49 PM

I figured the problem out it turns out the function itself is over the network, so in order for the variables to be stored right I need to send them over the network also, I ended up with this:

 void OnServerInitialized(){
 PlayerNames.Add(PlayerName);
 Debug.Log("SERVER");
 Debug.Log(PlayerNames[0]);

}

 void OnConnectedToServer(){
 networkView.RPC("SetServerInfo",RPCMode.All,PlayerName);

}

 void  SetServerInfo(string PN){
 PlayerNames.Add(PlayerName);
 Debug.Log("CLIENT");
 Debug.Log(PlayerNames[1]);

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to pass variables in a Network using RPC function(s) 0 Answers

Adding Entered name as Player 0 Answers

Assigning varaibles to prefabs 1 Answer

How do I make variables update on a network script? 1 Answer

I have a problem with variables/networking. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges