- Home /
Scripts not functioning or interacting.
Ok, so after the last time I posted this thanks to a few kind people, I saw that I had glazed over some just stupid things that I didn't think about when originally writing my scripts. Now I have removed those aspect and added a few log entry calls so whenever an action is performed it's logged.
Anyways to the point my scripts are still not interacting the way I wan't them to or not at all.
The script I have checking the number correct doesn't seem to work if I assign the adding of numbers to any function other than Update and if I set it in update it simply adds 1 to the number every frame the second the game is started.
The script in question:
#pragma strict
var correct : int = 0;
var callTrue : boolean;
function Start() {
correct = 0;
callTrue = false;
}
function Update(){
if(correct == 25){
Debug.Log("Win");
}
}
function Go(){
correct = correct + 1;
Update();
}
And just in case you wan't the script making the calls to this one.
#pragma strict
var checkTrue = boolean;
var correctCor : Vector3;
var card : GameObject;
function Update () {
var ArrayScript : ArrayCorrect = GetComponent(ArrayCorrect);
if(card.transform.position == correctCor){
Debug.Log("I'm at the spot D:");
ArrayScript.Go();
Debug.Log("Adding one to ArrayCorrect.js");
}
}
I'm sure I'm just glazing over something but sometimes I genuinely need other people to just point things out for me that I would otherwise catch.
Thanks in advanced.
At the moment you don't have a valid question. You have thus far stated you're not happy with how things are, but not said how you want them to change - how can anyone help you? What is it that you want to do that you need help with achieving?
Right, after reformatting your code, you are calling the Update() function. This function will be called automatically every frame by Unity anyway, it is a special function, calling it yourself will cause issues. You are calling "Go" from one Update which in turn calls an Update() on your other script, which will also run by itself when Unity calls Update during each frame...
Answer by MrSoad · Oct 31, 2014 at 11:44 PM
Try this, I've stripped out everything that is not specific to your code above :
#pragma strict
var correct : int = 0;
//I've removed your Start() function
//As far as this is concerned you
//are setting the "correct" value above
//and it is unnecessary.
function subGo(){
correct = correct + 1;
}
and :
#pragma strict
var correctCor : Vector3;
var card : GameObject;
var ArrayScript : ArrayCorrect;
//Find your script here, not every frame!
function Awake() {
//I'm assuming your ArrayCorrect is on the same
//object as this script.
ArrayScript = GetComponent(ArrayCorrect);
}
function Update() {
if (card.transform.position == correctCor) {
ArrayScript.subGo();
}
if(ArrayScript.correct == 25) {
Debug.Log("Win");
}
}
If you are having problems formatting your code here properly let us know, we can help, if you write your code like in your question then try and learn how to format it better. You, I, and everyone here will be able to read it better and figure out your problem faster if you do :)
Sorry all for the repeated edits, I have had a little bit of wine :)
Ok, for the most part this works. The counter doesn't go up until the object is moved to the correct coordinates but when it is the counter then just goes up by 1 every frame. How would I go around to having it add only 1 to the counter and then stopping it?
Edit: Never $$anonymous$$d I got it to work by having it destroy the script after poking the other script!