Unity-Tutorials.com
Professional Tutorials for the Unity 3D Game Engine |
|
| View previous topic :: View next topic |
| Author |
Message |
Aoleon
Joined: 26 May 2010 Posts: 7
|
Posted: Sun May 30, 2010 8:16 am Post subject: Your Introduction to Scripting Tutorial |
|
|
Hi,
I just watched your introduction to scripting.
I have a few questions and issues.
1) What are the {} brackets for? You don't tell us when and how to use them.
2) When I copied your move object script and used it in one of my own unity scenes I get the following errors...
Here is the script...
| Code: | var moveSpeed : float = 5;
function Update ()
{
if (Input.GetKey(KeyCode.UpArrow)) {
transform.Translate(Vector3(0,moveSpeed * Time.deltaTime,0));
}
else {
if (Input.GetKey(KeyCode.DownArrow)) {
transform.Translate(Vector3(0,-moveSpeed * Time.deltaTime,0));
}
if (Input.GetKey(KeyCode.RightArrow)) {
transform.Translate(Vector3(moveSpeed * Time.deltaTime,0,0));
}
else {
if (Input.GetKey(KeyCode.LeftArrow)) {
transform.Translate(Vector3(-moveSpeed * Time.deltaTime,0,0));
}
}
}
fuction Start ()
{
while (true) {
Debug.Log(transform.position.ToString());
yield;
}
} |
Here are the errors...
| Quote: | - Finished compile Library/ScriptAssemblies/Assembly - UnityScript - first pass.dll
Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js(19,2): BCE0044: expecting }, found ''.
(Filename: Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js Line: 19)
Updating assets/standard assets/scripts/active scripts/gui scripts/cameramove.js - GUID: 2f8cefd05223d4fbf81dd4552c47c7c9...
Calculating changed assemblies
End Calculating changed assemblies
- starting compile Library/ScriptAssemblies/Assembly - UnityScript - first pass.dll
done: hash - a37433e1005938a626ec5ea0e6946151
BCE0042: Error reading from 'Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js': 'null reference for: item'.
- Finished compile Library/ScriptAssemblies/Assembly - UnityScript - first pass.dll
Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js(21, : UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js Line: 21)
Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js(21,17): UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js Line: 21)
Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js(23,9): BCE0043: Unexpected token: while.
(Filename: Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js Line: 23)
Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js(23,21): UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js Line: 23)
Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js(24,57): BCE0044: expecting :, found ';'.
(Filename: Assets/Standard Assets/Scripts/ACTIVE SCRIPTS/GUI SCRIPTS/CameraMove.js Line: 24)
|
|
|
| Back to top |
|
 |
GargerathSunman
Joined: 20 Jul 2009 Posts: 47
|
Posted: Wed Jun 09, 2010 4:09 pm Post subject: |
|
|
You missed a down bracket after these lines:
| Code: | if (Input.GetKey(KeyCode.DownArrow)) {
transform.Translate(Vector3(0,-moveSpeed * Time.deltaTime,0)); |
Put one there and you'll be fine.
The brackets mark what statement you're currently inside in the script. The up bracket, {, marks an entrance to a statement and the down bracket, }, marks an exit. All if statements, loops, and functions need them so the code knows where you currently are.
| Code: | if (upBracket) {
downBracket = true;
} |
Whenever you have more up brackets than down brackets, it can't figure out where the exit is and runs a gigantic list of errors like the ones you saw. _________________ Bringing you the best in the simplest way possible.
http://www.unity-tutorials.com |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|