- Home /
Major errors on Build/export of game (CODING HELP NEEDED)
I've run into another, sadly far more complicated problem. So i've been working on a small indie horror game, and I've been periodically exporting and uploading a web version of my game to show my friends and colleagues my progress. This has all been great until very recently something has gone awfully wrong in the scripting. Along the way, I have always been getting a few warning or a error or two, but it will still let me play it in the unity editor and export it. Very recently, I was experimenting with a zombie enemy in my game, and It't hard to explain, but all of a sudden when I export (or "build it or whatever") my game pretty much all of my scripted objects vanish in the game, and I have a flashlight that you can pickup and then turn on and off, but now you start out with the flashlight for some reason, and everything is just totally screwed. I've been trying every thing I know and I just can't fix it.
I suspect it has something to do with the whole #pragma strict thing. I don't really know exactly know what #pragma strict function does, but I know that it has something to do with dynamic coding and every time I make a new JavaScript that It always adds it, and I always take it away. If I add it to pretty much any off my functions then it causes errors like so-
Assets/Scripts/ZombieKill.js(32,15): BCE0019: 'enabled' is not a member of 'Object'.
....
Here is one of my scripts for example, I don't know if this will help. This is the "zombie kill" script that makes it to where if my player walks into the zombie's Box Collider, then a red texture and text pops up saying "You Died" and then you are sent back to the main menu.
var Noise:AudioClip;
private var ydtexture;
private var ydtext;
private var look;
private var notei;
private var crosshair;
private var pause;
private var icon;
function Start()
{
ydtexture = gameObject.Find("YouDied").GetComponent("GUITextur e");
ydtexture.enabled = false;
ydtext = gameObject.Find("ydtext").GetComponent("GUIText");
ydtext.enabled = false;
look = gameObject.Find("Player").GetComponent("RBFPSContr ollerLogic");
crosshair = gameObject.Find("Player").GetComponent("AdvancedCr osshairSG");
icon = gameObject.Find("Player").GetComponent("chEnhancer ");
//crosshair.enabled = true;
notei = gameObject.Find("NOTEgui").GetComponent("ShowPaper ");
notei.enabled = true;
pause = gameObject.Find("Player").GetComponent("PauseMenu" );
pause.enabled = true;
}
function OnTriggerEnter (other : Collider) {
if(other.tag == "Player" && this.enabled) {
audio.PlayOneShot (Noise);
ydtexture.enabled = true;
ydtext.enabled = true;
look.enabled = false;
icon.enabled = false;
crosshair.enabled = false;
notei.enabled = true;
pause.enabled = false;
yield WaitForSeconds (4);
Application.LoadLevel(0);
}
}
So, I was hoping that maybe you know a thing or two about scripting and you could help get me out of this Awful predicament. Thank you so much for your time.
Email- sammygray123@gmail.com
Sincerly, Sam
Answer by Eric5h5 · Jul 20, 2013 at 08:58 PM
Never use the Array class (use built-in arrays or generic Lists instead), and always define the type of all variables, either explicitly, or implicitly by declaring a value. e.g., "var x;" is wrong, "var x = 5;" is fine, "var x : int;" is fine. Also never use quotes in GetComponent.
Could you explain the array part a bit more. I'm sorry i'm just very new, and I'm trying very hard to learn. By the way I went and edited the code part of the post like you said so it's easier to read. And what if the variables i'm using are not intriguers. How would I fix this problem all together, I know its a hassle but if you could post I fixed code It would help me SO $$anonymous$$UCH, I just need one working example to base my other codes off of so everything does screw over when I export it.
var foo : Array; // wrong
var foo : int[]; // good
var foo : List.< int >; // good
var foo = GetComponent("GUITexture"); // wrong
var foo = GetComponent(GUITexture); // right
what if the variables i'm using are not intriguers
Use whatever type is appropriate.
so, Since the variables are scripts, would it be var look : $$anonymous$$onoScript; ?? and would the GUIs be var ydtexture : GUITexture; ??
also, should the variables be written as var, private var, or public var
Since the variables are scripts, would it be var look : $$anonymous$$onoScript; ??
No, the type is the name of the script.
var look : RBFPSControllerLogic;
Variables should be private unless they need to be accessed from other scripts. "var" and "public var" are the same thing.
Ok, so I went and did everything you said like defining the variables and taking the quotation marks away, BUT IT STILL DOESN'T WOR$$anonymous$$ :( .... like I said before, it works just fine in the editor, and I don't get any errors, BUT when I export it to a web-build or standalone build (i've tried both regular export AND development build) It still screws up, and some of my scripted stuff disappears forsome reason.
Your answer
Follow this Question
Related Questions
Collisions arn't working properly 0 Answers
Help !! MIssing Semi colon in my coding 1 Answer
Ball jumping mechanic, scrip errors. 1 Answer
Why am I getting this error repeatedly? 2 Answers