- Home /
global variables possible in unityiphone 1.5.1
global variables possible in unityiphone 1.5.1 I'm using the scripts example from unity site but I seem to get a "fail" when building in xcode
// The static variable in a script named 'TheScriptName.js' static var someGlobal = 5;
// You can access it from inside the script like normal variables: print(someGlobal); someGlobal = 1;
To access it from another script you need to use the name of the script followed by a dot and the global variable name.
print(TheScriptName.someGlobal);
TheScriptName.someGlobal = 10;
Is this a question or a statement? If it is a question, could you make your question more clear? If it is a statement, then this should not be a question. :)
Answer by jtbentley · Aug 31, 2010 at 01:55 AM
You can't access it dynamically like that on an iphone due to a lack of dynamic typing.
You would need to do this in your other script..
var someGlobal = TheScriptName.someGlobal;
function Start() { print ("result : "+someGlobal); }
The change on script worked in the editor by using your suggestion and also not using capital on beginning of scriptname, but it doesn't build in xcode 3.1. Is it because I need to use xcode4?
Below is the error response after trying to build. OH SO CLOSE! Any suggestions? I've been hacking away at using global variables all day and I'm stumped.
ld: ldr 12-bit displacement out of range (6000 max +/-4096) in _AudioQueueAddPropertyListener$stub in _AudioQueueAddPropertyListener$stub from /Users/madpoet/balltest/balltest/build/testunity.app/testunity
Update:
I kept getting build errors when using Global (static) variables so I tried switching the sdk setting from UNITY , project setting, player to sdk 3.0 and now it builds w/o errors, BUT...will this cause problems later when I upgrade to sdk 4? I'm assu$$anonymous$$g unityiphone1.5.1 works w/sdk4 and is compliant w/new appstore requirements.
THX FOR ANY HELP!!
Your answer
Follow this Question
Related Questions
Changing static variables from another script? 1 Answer
Accessing a global variable's referenced object's variable 1 Answer
Global variables help 1 Answer
My static variable is not changing 2 Answers