View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:07 am



Reply to topic  [ 14 posts ] 
 Problems with SetMagnitude... Again. 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Problems with SetMagnitude... Again.
That's the same as this:

Code:
80


You need a variable.

Code:
numberofsheep = 80


Like that.


Tue Jun 15, 2010 11:25 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

Users browsing this forum: No registered users


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.081s | 13 Queries | GZIP : Off ]