- Home /
Javascript Class Update
Hi
I have a class established like so:
public class TowerClass{
//RUNS EVERY FRAME
function think(){
....
}
//SET THE TYPE OF TOWER
function settype(type:int){
....
}
}
I can access the settype() method in a separate script fine. In my main script I am trying to manually update the class think() via the Update() function. The main Update() looks like this:
function Update () {
keys.Update();
for(i = 0; i<18; i++){
for(n = 0; n<12; n++){
m.towerarray[i][n].think();
}
}
}
For some reason the think() method is never being called, or at least never run. There are no errors.
Have I misunderstood how the Update() function works?
Thanks
I am not sure why, but someone has edited my post so the code is no longer set out as it once looked. Any reason why they bunched it all up into one paragraph?
Answer by almo · May 19, 2011 at 09:43 PM
Have you verified that Update is being called? The script containing the Update function must be on a GameObject somewhere to have Update called on it.
Answer by oukie · May 19, 2011 at 10:26 PM
The Update() function is definitely being called, but I don't think the, think() is being run at all.
Use comments to give a comment ;) How is your array defined? Is it a typed array? If it's a dynamic typed array it could be that you have to cast it to the right type but you should get some kind of error if that's the reason. Are you sure that think is not called? Put a Debug.Log();
in your think-function.
Ah, the Debug Log worked in my think function. I was originally testing by printing and for some reason that was not working. Is there any reason why that would not work but the Debug does?