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 Golden · Nov 29, 2012 at 09:16 PM · function

How To Call a function from an other Script

Hi everyone,

I finished my big Script page about my dialogue system. And there is in this DialogueScript a main function with many arguments (like classes(that returns GameObjects, tabs of textures, booleans... ),variables etc...) which have also other function inside. This work nicely when I call my main function on same script's function start. But, I want to call this main dialogue function from other GameObjects. (for me it would be clearer, and easy to put specific dialogue from a specific npc)

To see what happened if I call my function from other script, I didn't put a specifique interact. So I wrote this on the NPCScript : (Sorry I'm Frensh so, some variables and classes are in frensh word... ^^' hope you understand a little)

     //NPCScript
     
     var ScriptObject : GameObject;
     
     
     function Start () {
      
     var Scripts = ScriptObject.GetComponent("DialogueScripts") ;
      
     Scripts.dialogueN(EtatDialogue.debut,false,false,"",Scripts.backgrounds[0],"Salut mec !","Il fait beau aujourd'hui !","Tu veux jouer avec moi ?",new PersoDialogue(Personnage.ten,TypeEmotion.content,"Ten",true,true),PortraitTrans.tVersDroiteEntreeG,new PersoDialogue(Personnage.personne,TypeEmotion.normal1st,"",false,false),PortraitTrans.apparition,new PersoDialogue(Personnage.personne,TypeEmotion.normal1st,"",false,false),null);
 }

So my questions are : How to call my function with arguments that are from other script without copy and past all classes, variables etc... on the NPC script ? Do I have to put into each argument a "Scripts.", or maybe something else ?

I tried many things... And still not working. I have always this issues :

BCE0005: Unknown identifier:'backgrounds'. BCE0005: Unknown identifier:'dialogueN'.

I wish you a nice day, and thank you in advance to help me.

Friendly,

Golden.

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

3 Replies

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

Answer by Golden · Nov 30, 2012 at 08:53 AM

Ok ok, i'm dumb... In my NPCScript I have always changed only my first line instead of all functions calls... (yes because I called many time my function to have a interveiw between 2 characters) , I've just forgot to add other calls function with "Scripts." So now It's working perfect ! May my question and my answer be usefull for everybody. Ashamed

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
avatar image
0

Answer by azmat786n · Nov 30, 2012 at 09:07 AM

script 1

 static function myFunction () {
 
     doSomething()
 }

script 2

 function Update() {
 
     if(Input.GetMouseButton(0)) {
 
     script1.myFunction();
 
     }
 }
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 fafase · Nov 30, 2012 at 09:16 AM 0
Share

mmmm, could work but I think he said that he has many game objects with that dialogue thing. Static won't do here. On top of that what if the function needs access to non-static variables? By the way he said he found the issue about 20 $$anonymous$$utes ago.

avatar image
0

Answer by CuddleMonster · Nov 30, 2012 at 08:56 AM

You are trying to send Variables inside the function's brackets? functionname ( var1, var2, var3 )?

you can only send one variable in a function, unfortunately. but you can send an array containing many variables.

 //Calling it
 
 var DialoguePackage = new Array( String1, Integer1, String2, Transform1 );
 
 function Dialogue ( DialoguePackage );
 
 
 
 // the function itself
 
 function Dialogue ( DialoguePackage : Array ) {
 
 //here you can use your previous variables but by their "packed" name.
 
 var ExampleVariable : int = 5 + DialoguePackage[1];
 
 
 
 
 }
Comment
Add comment · Show 3 · 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 fafase · Nov 30, 2012 at 09:02 AM 0
Share

???? What? you can only send one variable (aka parameter) to a function?? So this function below won't work then...

Vector3.Distance(vec1, vec2);

Damn I have been using a few times already....

And what is this array you are creating?? Do you mean ArrayList??

avatar image CuddleMonster · Nov 30, 2012 at 04:31 PM 0
Share

As far as I know you cant send more than one var in a function. I had to send Arrays for when I built a server sided Damage/Health script.

the Array here is slightly different from ArrayList. It is called a Javascript Array. It is more efficient than an ArrayList (I could be wrong) and its downside is it cannot be resized. (no need to resize it in this situation) http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

avatar image CuddleMonster · Nov 30, 2012 at 04:34 PM 0
Share

$$anonymous$$Y BAD! I was wrong. I was thinking of "Send$$anonymous$$essage" in which you cannot have more than one parameter.

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

13 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

Related Questions

Is there a way to break out of a function and return control to another script's function? 1 Answer

set a var to a function in another script 2 Answers

Function is called twice and I've no idea why 1 Answer

Script to run function every X minutes? 2 Answers

rot not working for 2nd prefab 2 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