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 Idahansen · Jul 21, 2012 at 01:10 AM · networkingstringchat

Question regarding chat-input?

Hi Forum, I've been using some of the networking-assets like chat-javascript, and learning a lot from them, again thanks to anyone who share work online, it helps new comers study code and how-to. But a lil' ill confused on this, how do I check for a specific string type, and sends a defined message from it. E.g. If someone were to type /smile, then it would send a specific message like "Smiles".

var skin : GUISkin;

private var inputField = ""; private var display = true; private var entries = ArrayList(); private var scrollPosition : Vector2;

private var window = Rect(50, 50, 351, 250);

function OnGUI () { GUI.skin = skin;

window = GUI.Window (1, window, GlobalChatWindow, ""); }

class ChatEntry { var sender = ""; var text = ""; var mine = true; }

function GlobalChatWindow (id : int) { scrollPosition = GUILayout.BeginScrollView (scrollPosition);

for (var entry : ChatEntry in entries) { GUILayout.BeginHorizontal();

if (!entry.mine) { GUILayout.Label (entry.text, "chat_leftaligned"); GUILayout.FlexibleSpace (); } else { GUILayout.Label (entry.text, "chat_rightaligned"); GUILayout.FlexibleSpace (); }

GUILayout.EndHorizontal(); GUILayout.Space(3);

}

 GUILayout.EndScrollView ();
 

if ( Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length > 0) {

ApplyGlobalChatText(inputField, 1); networkView.RPC("ApplyGlobalChatText", RPCMode.Others, inputField, 0); inputField = ""; }

GUI.SetNextControlName("Chat input field"); inputField = GUILayout.TextField(inputField);

GUI.DragWindow(); }

@RPC function ApplyGlobalChatText (str : String, mine : int) { var entry = new ChatEntry(); entry.sender = "Not implemented"; entry.text = str; if (mine == 1) entry.mine = true; else entry.mine = false;

entries.Add(entry);

if (entries.Count > 50) entries.RemoveAt(0);

scrollPosition.y = 1000000; }

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Jul 21, 2012 at 07:37 AM

Don't know a thing about chat/networking, but based on the code, I'd say adding this:

 if ( Event.current.type == EventType.keyDown && Event.current.character == "n" && inputField.Length > 0) {
 
 if(inputField == "/smile")  //add these lines
 inputField = "Smile!";
 
 ApplyGlobalChatText(inputField, 1); networkView.RPC("ApplyGlobalChatText", RPCMode.Others, inputField, 0); inputField = ""; }

should give you an idea I think..

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to put a list of strings in a Text Unity 4.6 UI element 3 Answers

Not able to convert GetComponent ().netId to a string. 0 Answers

Strange string appending 0 Answers

List of string is duplicated [C#] 1 Answer

Simple XML reading? (only string/numerical data needed) 1 Answer


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