View unanswered posts | View active topics It is currently Thu Mar 28, 2024 10:36 am



Reply to topic  [ 8 posts ] 
 MOPixel won't stay put? 
Author Message
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post MOPixel won't stay put?
How come this script doesn't work? :-(

Code:
function Create(self)
   self.StartPos = self.Pos;
   self.StartVel = self.Vel;
end
function Update(self)
   self.Pos = self.StartPos;
   self.Vel = self.StartVel;
end


Wed Sep 14, 2011 1:39 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: MOPixel won't stay put?
And if you pin the MOPixel and give it a speed with lua?


Wed Sep 14, 2011 1:52 am
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: MOPixel won't stay put?
No, Nonsequitorian, I need it to retain its speed, that way the trail still shows.


Wed Sep 14, 2011 1:54 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: MOPixel won't stay put?
If it doesn't change positions it won't have speed.


Wed Sep 14, 2011 2:11 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: MOPixel won't stay put?
No, if it doesn't change positions, it will still have speed, as long as the velocity is >0.
Currently, self.StartPos and self.StartVel are storing a reference to self.Pos and self.Vel, respectively. That means every Update, you're essentially doing this:
Code:
   self.Pos = self.Pos;
   self.Vel = self.Vel;

Lua is a bit weird like that. To do what you want, set the variables like so:
Code:
   self.StartPos = Vector(self.Pos.X, self.Pos.Y);
   self.StartVel = Vector(self.Vel.X, self.Vel.Y);


Wed Sep 14, 2011 2:21 am
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: MOPixel won't stay put?
Cortex Command is wierd :0


Wed Sep 14, 2011 2:25 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: MOPixel won't stay put?
Not really. Self.Pos is not a constant, and will change throughout the game. Self.Pos.X and Self.Pos.Y are constants at the time you reference them, so you have to reconstruct the Vector for the two inter-frame-constant variables in order to give a true starting value.

Which is exactly what TLB said in more words.


Wed Sep 14, 2011 5:19 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: MOPixel won't stay put?
Iiiiiew references... I had to deal with them in Java using clone()... So much pain....

It worked.


Fri Sep 16, 2011 2:01 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.141s | 17 Queries | GZIP : Off ]