Hello. These are the scripts for the selecting the options for my game (mode, difficulty, etc.). How it works is that the menu is a bunch of toolbars. Each toolbar option selected represents a number, that number represents a number in a different script, which contains the functions that start the options (like “Standard difficulty=true”). But, when I set it all up, nothing happens (I am getting no errors), what is wrong? Thanks.
Here are the scripts (these are just the parts I need help with, thats why they are sparse)
This is the script with the GUI
static var ModeInt = 0;
var ModeStrings : String[] = [];
function OnGUI() {
ModeInt = GUI.Toolbar (Rect (240, 270, 500, 50), ModeInt, ModeStrings);}
function OnGUI() {
if (ModeStrings==2) ArcadeOptions.Mode == 2;}
Here is the “ArcadeOptions” Script (It is not destroyed so that when the game loads in the next scene it works).
static var Mode = float;
function Awake () {DontDestroyOnLoad (transform.gameObject);
if (Mode ==2) {Multiplier.mulscore = true; Projectile.normalscore = false;}
}
and here is the “Projectile” script.
static var normalscore = true;
if (normalscore == true){
Stats.Score +=100*Stats.Mul;
}
I program in C# more than Unityscript, but that sure doesn’t look like a valid way to declare a float. Also, although I can’t tell conclusively from this snippet, an enum is usually the right way to handle modes.
You don’t have “#pragma strict” enabled. With that on, the above would’ve been caught by the compiler…
That’s because you didn’t address the more essential erorr that I mentioned. When you have three errors, you can’t pick and choose which to fix, you must correct them all for proper operation.
And again, enable “#pragma strict”, and your compiler will spot more of your coding errors for you. You’ve had about ~20 active ‘script help’ threads in the past week, so that really should be a priority.
I don’t use UnityScript, but I don’t think adding ‘#pragma strict’ is going to ‘fix’ your errors for you (that’s not its purpose). If you’re still getting errors, perhaps you could repost your code (if it’s changed at all from what you posted earlier), and post the errors that you’re getting currently.
Really? If you added it to ArcadeOptions, it should’ve reported why the static var Mode line doesn’t work the way you intended. It’s at its best when you add it to any new files that you’re developing.
It won’t fix his errors for him, but it should catch more of his errors earlier, for example:
static var Mode = float;
...
if (ModeStrings==2) ArcadeOptions.Mode = 2;}
I changed the Static var Mode=float to “static var Mode = 5;”(I used 5 because I am only using 0-4 in the other script, bit I guess that doesn’t really matter) and I am getting no errors with “#pragma strict” in both the GUI and ArcadeOptions scripts. Anyways, I still have into a somewhat hard to explain problem.
If I define something to happens in the script that has the toolbat GUI like this, the other variable (in this case, “Score”) works. Its changed to whatever is defined.
if (ModeInt==2) {Stats.Score=1000}
I then try to make a variable in the GUI script affect a variable in the “ArcadeOptions” script:
if (ModeInt==0) {ArcadeOptions.Mode =2;}
Here is the ArcadeOptions Script
#pragma strict
static var Mode = 5;
if (Mode ==0) {Stats.Score=1000;}
and it works, the Score value is changed.
The problem happens when I try to have the “ModeInt==” something other than 0(so that other buttons can affect the “ArcadeOptions” script). No matter what the element of that toolbar is, if it is not 0, nothing happens in the other script, what is going on(I am getting no errors from unity)?