Forum

Finding out 'what frame is the .mdl currently in?'

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Finding out 'what frame is the .mdl currently in?'

Postby OneManClan » Tue Jun 28, 2011 5:43 am

Hi all,

How can a function find out which animation frame 'self' is currently in? Specifically, I'm trying to make a touch function only trigger if the .mdl is in a specific frame.

It might be easier to explain with this simplified demonstration code:

Code: Select all
    PSEUDOCODE
     
    // find the frames
    $cd /quake/fortress/progs/john
    // declare the frames
    $frame john1 john2 john3 john4
     
     
    // make functions to run the frames
    void()   john_frame1 =   [$john1, john_frame2   ] {};
    void()   john_frame2 =   [$john2, john_frame3   ] {};
    void()   john_frame3 =   [$john3, john_frame4   ] {};
    void()   john_frame4 =   [$john4, john_frame1   ] {self.nextthink = time + 20};
     
     
     
    local entity foo;
     
    foo = spawn();
     
    // makes the john.mdl appear wherever the foo entity is
    setmodel (foo, "progs/john.mdl");
     
    foo.touch = Func_1;
     
    john_frame1();
     
    ...
    };
     
    void Func_1 () =
    {
     
    // self is foo
     
    if ( foo is currently in john_frame4)
            {

            // (do something)

            // Q: how can Func_1 be told if we are in john_frame4?

           
            }
     
    };



thanks,

OneManClan
Last edited by OneManClan on Tue Jun 28, 2011 11:45 am, edited 2 times in total.
OneManClan
 
Posts: 243
Joined: Sat Feb 28, 2009 2:38 pm

Postby behind_you » Tue Jun 28, 2011 6:31 am

set a float equal to self.frame

It wont return the frame as $frame, but only as an integer, so you will probably have to figure out the integer value for every frame.
User avatar
behind_you
 
Posts: 237
Joined: Sat Feb 05, 2011 6:57 am
Location: Tripoli, Libya

Postby ceriux » Tue Jun 28, 2011 8:08 pm

the first frame is always 0 right? so start at 0 count to the one you're hoping its supposed to land on. and do a if (self.frame == x).

i think... i'm not the best at QC.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby frag.machine » Wed Jun 29, 2011 2:11 am

Code: Select all
 if (self.frame == $walk5) {
  // do something
}
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Wed Jun 29, 2011 9:53 am

void() john_frame1 = [$john1, john_frame2 ] {code();};


expands to:


void() john_frame1 =
{
self.frame = $john1;
self.think = john_frame2;
self.nextthink = time+0.1;

code();
};
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby OneManClan » Wed Jun 29, 2011 3:20 pm

Thanks guys.

Yes, it was self.frame all along. I got confused because there seem to be 2 different 'methods' for animation.

1. The 'Standard' way, ie described in all the QuakeC stuff I've been rtfming - Calling foo_animate1();
Code: Select all
// defaults to .1 frames per second, all the (required) stuff in the [...] bit can be overwritten in the {...} (code) section
void()   foo_animate1 =   [$foo1, foo_animate2   ] {};
void()   foo_animate2 =   [$foo2, foo_animate3   ] {};
etc..


2. The 'Walkframe' method. Using .walkframe to time the speed of the frames, and not using any animation functions
( don't know if this is standard, or a CustomTF thing) to decide when to switch to the next $frame
Code: Select all
if (self.walkframe >= 8) // eg. if 8 is the number of frames
            self.walkframe = 0;
self.frame = $foo1 + floor(self.walkframe);
// the 0.1 value can be manipulated to control the speed of the animation
self.walkframe = self.walkframe + 0.1;


Q: Is there any reason why the second method was created, and why one would choose 1 over the other? There's also a third method (that I know of) proposed by someone here in i3d recently, I'll add the link to the bottom of this thread if I find it.

Spike wrote:void() john_frame1 = [$john1, john_frame2 ] {code();};

expands to:

void() john_frame1 =
{
self.frame = $john1;
self.think = john_frame2;
self.nextthink = time+0.1;

code();
};


Thanks Spike. This "New .mdl Frames" tutorial describes the syntax as:
Code: Select all
  name =[framenum, nexttime, nextthink] {code};


.. but I've never seen 3 'arguments' in any '[ ]' section. What's the story?


OneManClan
ps. My little animation sequence is working beautifully, thanks everyone!
OneManClan
 
Posts: 243
Joined: Sat Feb 28, 2009 2:38 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest