Author |
Message |
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Problems with SetMagnitude... Again.
OK, frankly, I'm pretty sure this should work: Code: function Create(self) self.VelMag = 0; self.VelMag = self.Vel.Magnitude; self.NewV = Vector(0,0); end
function Update(self)
if self.Vel.Magnitude < 80 then self.NewV = self.Vel; self.NewV:SetMagnitude(self.VelMag); self.Vel = Self.NewV; end end
And yet it doesn't. When run, the console just returns "No overload of Vector:SetMagnitude(const.Vector,number) matched the arguments Vector:SetMagnitude(custom[float])". I also tried just typing self.NewV:SetMagnitude(80); , but that doesn't work either. Any thoughts on the reason?
|
Tue Jun 15, 2010 11:14 pm |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Problems with SetMagnitude... Again.
That's the same as this: You need a variable. Like that.
|
Tue Jun 15, 2010 11:25 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Problems with SetMagnitude... Again.
Eh, no? I changed the code to Code: function Create(self) self.NewMag = 80; self.NewV = Vector(0,0); end
function Update(self)
if self.Vel.Magnitude < 80 then self.NewV = self.Vel; self.NewV:SetMagnitude(self.NewMag); self.Vel = Self.NewV; end end And it still doesn't work.
|
Wed Jun 16, 2010 1:04 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Problems with SetMagnitude... Again.
What CaveCricket48 means is this: Code: self.NewV:SetMagnitude(self.NewMag); This doesn't actually change the variable; it returns a copy of the variable with the magnitude changed. You want this: Code: self.NewV = self.NewV:SetMagnitude(self.NewMag);
|
Wed Jun 16, 2010 1:28 am |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Problems with SetMagnitude... Again.
Gee, you're right! ...Even so, Code: function Create(self) self.NewMag = 80; self.NewV = Vector(0,0); end
function Update(self)
if self.Vel.Magnitude < 80 then self.NewV = self.Vel; self.NewV = self.NewV:SetMagnitude(self.NewMag); self.Vel = Self.NewV; end end Still doesn't work. Same error as before.
|
Wed Jun 16, 2010 1:34 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Problems with SetMagnitude... Again.
You capitalized the "S" in the last self. (ie. change Self.NewV to self.NewV)
|
Wed Jun 16, 2010 2:47 am |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Problems with SetMagnitude... Again.
You're right about that.
What doesn't affect the fact that the error appears on the SetMagnitude function, not on that line.
|
Wed Jun 16, 2010 2:50 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Problems with SetMagnitude... Again.
Try, instead of Code: self.NewV = self.Vel do Code: self.NewV = Vector(self.Vel.X,self.Vel.Y)) Do the same with all vector calling/setting. While both should have the same results, I've had instances where that's not the case.
|
Wed Jun 16, 2010 2:55 am |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Problems with SetMagnitude... Again.
That just did the trick. Which is kind of creepy, actually.
Many thanks to ye all.
|
Wed Jun 16, 2010 3:09 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Problems with SetMagnitude... Again.
I'm still curious why using SetMagnitude didn't work out right. Anyone know why?
|
Wed Jun 16, 2010 3:29 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Problems with SetMagnitude... Again.
It's an issue in the actual engine, which is written in C++. The function doesn't take a constant value, but apparently the variables are stored as constant values, while creating a new Vector is a different story.
|
Wed Jun 16, 2010 3:38 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Problems with SetMagnitude... Again.
That's really odd, but that does sort of make sense. Now I'm just wondering when the engine considers a Lua variable a constant and when it doesn't?
|
Wed Jun 16, 2010 6:52 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Problems with SetMagnitude... Again.
Presumably, at completely batshit insane times that are wholly unpredictable.
Remember, this is Cortex Command.
|
Wed Jun 16, 2010 8:04 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
Re: Problems with SetMagnitude... Again.
Grif wrote: Presumably, at completely batshit insane times that are wholly unpredictable.
Remember, this is Cortex Command. Because Data obviously coded it using the Miracle File System.
|
Wed Jun 16, 2010 8:54 pm |
|
|
|