SetLocation(vect(x, z, z)) does not compile

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2536
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

SetLocation(vect(x, z, z)) does not compile

Post by Barbie »

I tried this (v436 & v469b):

Code: Select all

if (A.SetLocation(vect(A.Location.x, -797, A.Location.z)))
and got
Error, Missing X component of vector
This in opposite compiles fine:

Code: Select all

local vector v;
	v = A.Location;
	v.y = -797;
	if (A.SetLocation(v))
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: SetLocation(vect(x, z, z)) does not compile

Post by Buggie »

form "vect(A, B, C)" expect A, B, C is a constant.
If you need set variables, then you need variable for that, like you do for second case.
User avatar
sektor2111
Godlike
Posts: 6133
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: SetLocation(vect(x, z, z)) does not compile

Post by sektor2111 »

This way is used by me whenever I need to move stuff:

Code: Select all

		if (string(A.Name) ~= "Trigger1") // Position 311
		{
			A.SetLocation(A.Location+vect(0,0,-768));
			A.Event = '';
			continue;
		}
See Niven hooligan mutator for destruction of doors in CTF-Niven, which I did a few time ago...
1337GameDev
Skilled
Posts: 198
Joined: Thu Apr 16, 2020 3:23 pm
Personal rank: GameDev

Re: SetLocation(vect(x, z, z)) does not compile

Post by 1337GameDev »

Barbie wrote: Sun Apr 11, 2021 12:05 pm I tried this (v436 & v469b):

Code: Select all

if (A.SetLocation(vect(A.Location.x, -797, A.Location.z)))
and got
Error, Missing X component of vector
This in opposite compiles fine:

Code: Select all

local vector v;
	v = A.Location;
	v.y = -797;
	if (A.SetLocation(v))
I encountered this recently too. You cannot set VARIABLES as the x,y, or z components when creating. It expects a compile time constant.

You NEED to create the struct first: eg: vector1 = Vect(0,0,0);.

THEN you can set x, y, and z.
Eg: vector1.X = variableX;

It's dumb, I know. A limitation of structs.