x


[iOS] Pass a Javascript name to a function in another script?

I found myself in a quite difficult situation. I have a script calling this custom function:

HorButton (SideX,5,25,"HOME",11,1,BackSxTEX,EmptyFillTEX,EmptyDxTEX,gameObject,MENU_MyShoes,MENU_LandingPage);

This function builds a dynamic horizontal button made up of three different parts and textures, with a variable lenght depending of the text lenght. Anyways, I need to pass to this function two different javascripts: one is MENU_MyShoes, wich is the script who's actually calling the HorButton function. The other javascript to pass is MENU_LandingPage, wich is the next menu that will be loaded after pressing the generated button.
And this is the whole function code. The problem is that I absolutely don't know what to insert where I wrote "?????":

public function HorButton ( SideX : float,  posX : int,  posY : int,  Testo : String,  Molt : float,  Dir : int,  TexSX : Texture2D,  TexCX : Texture2D,  TexDX : Texture2D,  obj : GameObject,  OldScript : String,  NewScript : String  ) {
/*Lots of GUI code here*/

if (GUI.Button(Rect((posX/HD)+SideX,posY/HD,(posX+TexSX.width+(Testo.length*Molt)+TexDX.width)/HD,TexCX.height/HD),Testo)){
    var NewMenu = gameObject.AddComponent(NewScript) as ?????;
    NewMenu.SideX = Screen.width*(-Dir);
    NewMenu.fase = "intro";
    var OldMenu = obj.GetComponent(OldScript) as ?????;
    if (Dir > 0)
       OldMenu.fase = "outroDX";
    else
       OldMenu.fase = "outroSX";
}

}

I literally have no clue on how to solve this, since I always end getting that "X is not member of Y" error... I don't know how to cache these two scripts. Keep in mind that this function must be reusable from a lot of different scripts, so the variables NewScript and OldScript must be able to read every Javascript I pass to them...

Thanks for everyone who can help!

more ▼

asked May 07 '12 at 04:02 PM

DanjelRicci gravatar image

DanjelRicci
380 17 20 31

To clarify: you want to call an arbitrary function from another function, and pass the name of that function via the parameters? Where does that other function live, and is static/globally accessible? Why are you trying to add the script to the gameObject's component list in the first place?

May 07 '12 at 08:56 PM Drakestar

I'm trying to do the exact same thing - pass a script name into a function by can't figure out what type to declare the variable "OldScript" or "NewScript". I started out with trying type "String" as well and got the same "not a member of" errors. Did you ever solve this? I would love to know!

Aug 25 '12 at 05:26 AM bkovner100
(comments are locked)
10|3000 characters needed characters left

0 answers: sort oldest
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3669
x1953
x477
x26
x7

asked: May 07 '12 at 04:02 PM

Seen: 504 times

Last Updated: Aug 25 '12 at 05:26 AM