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



Reply to topic  [ 13 posts ] 
 Yet Another Animation question 
Author Message
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Yet Another Animation question
Now, you can check what frame the animation is on with self.Frame == whatever, is there any similarly simple way to SET the frame, or is that impossible currently? Couldn't find anything about it in the wiki :oops:


Fri Feb 26, 2010 4:29 am
Profile YIM
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: Yet Another Animation question
self.Frame = 0
Sets self.Frame to 0. If the LuaDocs say it's read-only, then that's a lie.


Fri Feb 26, 2010 4:36 am
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Yet Another Animation question
Just like u put ^_^
Code:
function Update(self)
if alskdjas;ldkjad
self.Frame = (#);
end
end


unless im missing what you're asking. o-O

aw tlb


Fri Feb 26, 2010 4:36 am
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Yet Another Animation question
Good lord I put 2 equal signs. If this works I'm going to feel retarded again.


Fri Feb 26, 2010 4:41 am
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Yet Another Animation question
== checks
= sets


Fri Feb 26, 2010 6:03 am
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Yet Another Animation question
Yeah okay it works I'm just a retard. Second of all, once I set the frame, how do I get it to re-increment past that frame. Is there a function that will do it or do I have to make my own timer?

For reference here's my really basic code:

function Create(self)

end

function Update(self)
if self.Frame > 3 then
self.Frame = 1
end
end


Fri Feb 26, 2010 6:24 am
Profile YIM
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: Yet Another Animation question
Depending on what you're setting the frame of, you may have a problem with the object itself resetting its frame. Store a separate variable for frame (such as self.currentFrame) and work with that like you would normally work with frames. Then, at the end of Update, set self.frame to self.currentFrame.


Fri Feb 26, 2010 6:32 am
Profile WWW
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Yet Another Animation question
Here's my current (non-working) code. I'm trying to just have it animate completely by Lua, but I'm evidently doing something wrong. Also, even if this does work, there's no delay in between frames (not implemented yet - is there a better way than using IsPastSimMS() something or other?). The pseudocode for this is something like:

- Random choice between 1 and 6
- Depending on number chosen, start the frame at some number and continue to some other number (using a for loop, I assume)
- Once that number is achieved and it's below a certain altitude, settle it.

Any tips?

function Create(self)
self.lifetimer = Timer();
self.plantframe = 0;
end

function Update(self)
self.ToSettle = false;

local chance = math.random(1,1)
if chance == 1 then
for i = 1,6 do
self.plantframe = self.plantframe + 1;
self.frame = self.plantframe;
end

if self.Frame > 5 then
self.ToSettle = true;
end
end
end


Fri Feb 26, 2010 9:15 pm
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Yet Another Animation question
you could theoretically use self.age % <ms> as a timer, but in practice lua updates too slowly for that to work.

basic script that should accomplish what you want:

function Create(self)
self.frametohit = math.random(1,6);
self.currentframe = 0;
self.altitude = 10;
self.animtimer = Timer();
end

function Update(self)
if self.animtimer:IsPastSimMS(100) == true then
if self.currentframe < self.frametohit then
self.currentframe = self.currentframe + 1;
elseif self.currentframe == self.frametohit then
if self:GetAltitude(0,4) < self.altitude then
self.ToSettle = true;
end
end
end
self.Frame = self.currentframe;
end


Fri Feb 26, 2010 10:24 pm
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Yet Another Animation question
Here's the modified version of it which is probably closer to what I'm trying to get done - as it stands, it only goes to the first frame then stops. Augh.

Code:
function Create(self)
      self.minframe = 0;
      self.maxframe = 0;      
      self.lifetimer = Timer();
end

function Update(self)
   self.ToSettle = false;
   local chance = math.random(1,2)
   if chance == 1 then    
      self.minframe = 0;
      self.maxframe = 6;
      if self.lifetimer:IsPastSimMS(50) == true then
         if self.minframe < self.maxframe then
            self.minframe = self.minframe + 1;
         elseif self.minframe == self.maxframe then
            if self:GetAltitude(0,4) < 2 then
               self.ToSettle = true;
            end
         end
      end
   elseif chance == 2 then    
      self.minframe = 7;
      self.maxframe = 12;
      if self.lifetimer:IsPastSimMS(50) == true then
         if self.minframe < self.maxframe then
            self.minframe = self.minframe + 1;
         elseif self.minframe == self.maxframe then
            if self:GetAltitude(0,4) < 2 then
               self.ToSettle = true;
            end
         end
      end
   end
   self.Frame = self.minframe;
end


Fri Feb 26, 2010 11:55 pm
Profile YIM
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Yet Another Animation question
because you're setting minframe every update

like, think about it
if you're running that code every update frame, then you're constantly telling it to set minframe to either 0 or 7; the rest of the code is moot

try this:

http://lua.pastebin.com/Hbz6kgs7


Sat Feb 27, 2010 1:11 am
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Yet Another Animation question
Grif wrote:
because you're setting minframe every update

like, think about it
if you're running that code every update frame, then you're constantly telling it to set minframe to either 0 or 7; the rest of the code is moot

try this:

http://lua.pastebin.com/Hbz6kgs7


Bam, that works, I'll keep this aspect of Lua in mind, thank.


Sat Feb 27, 2010 5:51 am
Profile YIM
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Re: Yet Another Animation question
Hey look more garbage! I'm trying to get it to print frame upon hitting growthframe and it's not doing it and I'm just getting pissed off at it so I'll pray to the Lua pantheon once again for salvation.

Code:
function Create(self)
   self.minframe = 0;
   self.maxframe = 0;
   self.growthframe = 0;
   self.lifetimer = Timer();
   
   local chance = math.random(1,8)
   if chance == 1 then
      self.minframe = 1;
      self.maxframe = 6;
      self.growthframe = 3;
   elseif chance == 2 then
      self.minframe = 7;
      self.maxframe = 12;
      self.growthframe = 9;
   elseif chance == 3 then
      self.minframe = 13;
      self.maxframe = 18;
      self.growthframe = 5;
   elseif chance == 4 then
      self.minframe = 19;
      self.maxframe = 23;
      self.growthframe = 21;
   elseif chance == 5 then
      self.minframe = 24;
      self.maxframe = 29;
      self.growthframe = 26;
   elseif chance == 6 then
      self.minframe = 30;
      self.maxframe = 35;
      self.growthframe = 32;
   elseif chance == 7 then
      self.minframe = 36
      self.maxframe = 41;
      self.growthframe = 38;
   elseif chance == 8 then
      self.minframe = 42;
      self.maxframe = 47;
      self.growthframe = 44;
   end
end

function Update(self)
   self.ToSettle = false;
   if self.lifetimer:IsPastSimMS(150) == true then
      self.lifetimer:Reset();
      if self.minframe < self.maxframe then
         self.minframe = self.minframe + 1;
      elseif self.minframe == self.growthframe then
         print(self.Frame)
      elseif self.minframe == self.maxframe then
         if self:GetAltitude(0,4) < 2 then
            self.ToSettle = true;
         end
      end
   end
   self.Frame = self.minframe;
end


Sun Feb 28, 2010 6:44 am
Profile YIM
Display posts from previous:  Sort by  
Reply to topic   [ 13 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.052s | 13 Queries | GZIP : Off ]