Hey everyone! I have been working on a script for quite some time and it began to get a little confusing and unorganized. So I decided to locate certain parts of the code and write them instead as functions and then call that function whenever I needed it. Example:
function Update(){
Shoot();
}
function Shoot(){
does something here;
}
Well, I ran into a problem. Let’s say there is a variable called ammo inside function Shoot, and I need to access ammo in the Update function. Well, I can’t. I keep getting an error that says “Unknown identifier: ‘ammo’.” So, I thought, maybe I could make ammo a static var. When I did that, I got an error that said “expecting }, found ‘static’.” I have no idea what is going wrong. Also there is no } or { anywhere near the var ammo. Please help!
// variable available all through out the script
var ammo : int = 10;
function Update()
{
Shoot();
}
function Shoot()
{
// ammo readable in this function.
}
function Update()
{
// local variable only available in Update()
var ammo : int = 10;
Shoot(ammo); //
}
// shoot requires an int.
function Shoot (var ammo : int)
{
// ammo available in this function
}