x


Access a static var included on one script from another one

Hi,

I have a script to control the movement of an elevator. On this script I have a private var that controls the speed - elevSpeed.

I want to be able to control this variable using an Horizontal Slider defined on another script - therapistGUI.

How can I do this?

thanks,

more ▼

asked Mar 19 '10 at 09:06 PM

maveryck21 gravatar image

maveryck21
239 29 32 44

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I'll answer my own question because I was able to find the solution. I don't know if you prefer me to delete the question, but I think it can be useful for others.

To access a variable from another script we need to define it as a global variable:

static var elevSpeed

then to access from another script we just need to call the scriptName.globalVarName:

Elevator.elevSpeed

On this case I used the variable to control the speed of the elevator with an horizontal slider:

Elevator.elevSpeed = GUI.HorizontalSlider (Rect(25,185,100,25), Elevator.elevSpeed, 0.0, 10.0);

hope it helps other like me

more ▼

answered Mar 19 '10 at 09:13 PM

maveryck21 gravatar image

maveryck21
239 29 32 44

If you find the solution, answering your own question is perfectly fine. I think the only thing that's frowned on is creating questions you already know the answer to just to get points.

Mar 19 '10 at 10:29 PM Michael La Voie

LOOL do you really think I'm asking questions that I know the answers just to earn points? I ask questions because I have a work to finish..If I found the answer after asking I think its honest to say that I found it and to share with the other members of the forum..

Mar 20 '10 at 01:31 AM maveryck21

reguardless of why the question was posted, it helped me understand this principle. Thanks mavery.

Apr 22 '10 at 09:36 AM TinyUtopia

thanks! It was useful to me as well.

Jul 03 '10 at 06:40 PM Edy

Helpful to me as well - thanks - AlexisMichail

Dec 04 '10 at 04:46 PM schwertfisch
(comments are locked)
10|3000 characters needed characters left

thanks dude you helped me

more ▼

answered Feb 15 '12 at 04:47 PM

younse gravatar image

younse
1 1

This is not an answer, please leave a comment under the answer if you with to be thankful.

Oct 06 '12 at 07:25 PM thellama
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x3694
x103

asked: Mar 19 '10 at 09:06 PM

Seen: 2970 times

Last Updated: Oct 06 '12 at 07:25 PM