x


Before updating to Windows 10 you may need to return your Pro license. More information here

"Expressions in statements must only be executed for their side effects." ERROR.

I'm getting an "Expressions in statements must only be executed for their side effects." error. What am I doing wrong?

more ▼

asked Jul 27, 2010 at 05:56 AM

avatar image

MikezNesh
1.1k 181 152 167

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

It means you have a statement in your code that doesn't DO anything - it doesn't alter any state and thus doesn't have any effect on anything. That is seen as an error.

One example of this could be if you have a line like this (where MyFunction is a function declared elsewhere):

function Update () {
    MyFunction;
}

In this code there is a statement which just states the reference to MyFunction but doesn't do anything with it. If you wanted to call the function, you should remember the paranthesis:

function Update () {
    MyFunction();
}

Now the code actually calls MyFunction, so it's not seen as a coding error anymore.

more ▼

answered Jul 27, 2010 at 08:24 AM

avatar image

runevision ♦♦
9.9k 57 138 324

Thanks. Really like your locomotion system by the way :D

Jul 27, 2010 at 07:00 PM MikezNesh

Really concise, helpful answer. Thanks, man.

Jun 12 at 08:26 PM coughin05
(comments are locked)
10|3000 characters needed characters left

Could be several things...this error message is discussed here.

more ▼

answered Jul 27, 2010 at 06:27 AM

avatar image

Eric5h5
121k 79 361 774

(comments are locked)
10|3000 characters needed characters left

An additional example that's not a function missing brackets:

I've been stuck with this error for accidentally putting the statements of a For loop in the wrong order. Due to the rarity of the traditional For(Intialisation;Condition;Increment) structure in my code, (and lack of syntax reference in the help file) this elementary error took a while to spot.

Placing my order as For(Intialisation;Increment;Condition), it tried to treat a condition as a change. Which is how I think I got this error.

more ▼

answered Dec 03, 2010 at 03:19 PM

avatar image

Novodantis 1
1.9k 28 37 58

(comments are locked)
10|3000 characters needed characters left

x==1;

this is the same error must be

x=1;

more ▼

answered Aug 23, 2013 at 10:25 PM

avatar image

przem997
0

(comments are locked)
10|3000 characters needed characters left

I have a very big problem. When I build my script, MonoDevelop say this:

-Expressions in statements must only be executed for their side effects.This is my script:

var walkAcceleration : float = 5;

var cameraObject : GameObject;

var maxWalkSpeed : float = 20;

@HideInInspector

var horizontalMovement : Vector2;

function Update () { horizontalMovement = Vector2(GetComponent.().velocity.x, GetComponent.().velocity.z); if(horizontalMovement.magnitude > maxWalkSpeed) { horizontalMovement.normalized; horizontalMovement *= maxWalkSpeed; }

 GetComponent.<Rigidbody>().velocity.x = horizontalMovement.x;
 GetComponent.<Rigidbody>().velocity.z = horizontalMovement.y;
 
 transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).RotacionActualY, 0);
 GetComponent.<Rigidbody>().AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);

}

PD: I´m in Unity 5 Please Help Me!

more ▼

answered May 30 at 11:25 AM

avatar image

Albertounitytutoriales
1 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4423
x213
x10
x6

asked: Jul 27, 2010 at 05:56 AM

Seen: 17814 times

Last Updated: Jun 12 at 08:26 PM