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 Zyphen · Jun 14, 2013 at 09:40 PM · javascriptmultiplayernew

How to call a function from another script?

Okay so I have a script called MenuManager and I'm trying to tell it to run the function StartServer in my MultiplayerManager script. obviously I'm new to this and I'm following a tutorial but this scripts are in c# and I'm recreating them in JavaScript. I have tried searching for this already but couldn't solve it. so here are the two scripts: (im trying to call the function on line 53)

 // Variables 
 var CurrentMenu;
 var MatchName : String;
 var MatchPassword : String;
 var MatchMaxPlayers : int = 32;
 
 
 
 function Start () 
 {
     CurrentMenu = "Main";
     
 }
 
 
 
 function OnGUI()
 {
      if(CurrentMenu == "Main")
      Menu_Main();
      
      if(CurrentMenu == "Lobby")
      Menu_Lobby();
      if(CurrentMenu == "Host")
      Menu_HostGame();
 }
 
 public function NavigateTo(nextmenu)
 {
     CurrentMenu = nextmenu;
 }
 
 private function Menu_Main()
 {
     if (GUI.Button(new Rect(10,10,200,50), "Host Game"))
     {
         NavigateTo("Host");
     }
 }
 
 private function Menu_HostGame()
 {
     //Buttons Host Game
 if (GUI.Button(new Rect(10,10,200,50), "Back"))
     {
         NavigateTo("Main");
     }
 // Start Server Button    
 if (GUI.Button(new Rect(10,60,200,50), "Start Server"))
     {
 // THIS IS WHERE I WANT TO CALL IT FROM    
         MultiplayerManager.Instance().StartServer;
     }
 //Text boxes and lables    
 GUI.Label(new Rect(220, 10, 130, 30), "Match Name");
 MatchName = GUI.TextField(Rect(400, 10, 200, 30), MatchName);
 
 GUI.Label(new Rect(220, 50, 130, 30), "Match Password");
 MatchPassword = GUI.PasswordField(Rect(400, 50, 200, 30), MatchPassword, "*"[0],25);
 
 GUI.Label(new Rect(220, 90, 130, 30), "Maximum Players");
 GUI.Label(new Rect(400, 90, 200, 30), MatchMaxPlayers.ToString());
 MatchMaxPlayers = Mathf.Clamp(MatchMaxPlayers, 8, 32);
 
 if (GUI.Button(new Rect(425,90,25,30), "+"))
 {
     MatchMaxPlayers += 2;
 }
 if (GUI.Button(new Rect(450,90,25,30), "-"))
 {
     MatchMaxPlayers -= 2;
 }
 
 
 }
 
 private function Menu_Lobby()
 {
 
 }

And here is the MultiplayerManager script:

 public class MultiplayerManager extends MonoBehaviour
 {
     private static var instance:MultiplayerManager;
     
     public static function Instance():MultiplayerManager
     {
         return instance;
     }
     
     public function StartServer()
     {
     
     
     }
 }
 

 
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 create3dgames · Jun 14, 2013 at 09:46 PM 0
Share

Do you get any errors?

avatar image Zyphen · Jun 14, 2013 at 10:09 PM 0
Share

Well currently it just says the "Expressions in statements must only be executed for their side-effects."

avatar image Zyphen · Jun 14, 2013 at 10:10 PM 0
Share

Also when currently i can access the $$anonymous$$ultiplayer$$anonymous$$anager from the $$anonymous$$enu$$anonymous$$anager but thats as far as it goes, i dont know how to call the function after that

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer Wiki

Answer by Ziethriel · Jun 15, 2013 at 12:42 AM

You're trying to call two functions from the same action. The error is "Expressions in statements must only be executed for their side-effects." because you don't have () behind the second function.

Right now your dot syntax suggests that StartServer is a part of the function Instance(). Try This:

// THIS IS WHERE I WANT TO CALL IT FROM MultiplayerManager.Instance(); MultiplayerManager.StartServer();

Comment
Add comment · Show 1 · 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
avatar image Zyphen · Jun 15, 2013 at 10:00 AM 0
Share

Cheers for that, i just changed it to $$anonymous$$ultiplayer$$anonymous$$anager.StartServer(); and then changed StartServer to static and it works perfectly! thanks alot

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

setup a php master server 2 Answers

Adding force to a projectile? (SOLVED) 1 Answer

How do I add gravity to my object, and how do I fix my network problem? 1 Answer

Script Not Working At All.... :) (SOLVED) 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