Forum

while loops in qc?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

while loops in qc?

Postby sniperz227 » Sat Dec 10, 2011 4:56 am

hey i was writing a function that basically says if the user shoots 3 continious shots and continues to then change the punchangle and the accuracy. when i tested it out i got an error when i tried shooting in dakrplaces but when i changed the while to an if it was fine.

Code: Select all
void () W_FireM9 =
{
   local .float shots_fired;
   self.shots_fired = 15 - self.exam_m9;

   local vector dir;

   sound (self, CHAN_WEAPON, "weapons/m9.wav", 1, ATTN_NORM);
   
   self.punchangle_x = -2;

   self.currentammo = self.exam_m9 = self.exam_m9 -1;
   dir = aim (self,100000);
   FireBullets (1,dir, '0.03 0.04 0');
   
   while (self.shots_fired = self.shots_fired -3)

   {
      self.punchangle_x = -5;
      FireBullets (1, dir, '0.05 0.06 0');
   }
   
   

};


thanks
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: while loops in qc?

Postby taniwha » Sat Dec 10, 2011 7:31 am

sniperz227 wrote:
Code: Select all
   while (self.shots_fired = self.shots_fired -3)


That should be ==, not =. = is assignment, == is comparison.
Leave others their otherness.
http://quakeforge.net/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Re: while loops in qc?

Postby sniperz227 » Sat Dec 10, 2011 5:28 pm

it worked like it doesnt crash anymore but the code doesnt work :P
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: while loops in qc?

Postby taniwha » Sun Dec 11, 2011 12:14 am

sniperz227 wrote:it worked like it doesnt crash anymore but the code doesnt work :P

Actually, I noticed what you were trying to do. This is the right way:
Code: Select all
while (self.shots_fired >= 3) {
    ...
    self.shots_fired = self.shots_fired -3;
}
Leave others their otherness.
http://quakeforge.net/
taniwha
 
Posts: 399
Joined: Thu Jan 14, 2010 7:11 am

Re: while loops in qc?

Postby Error » Mon Dec 12, 2011 10:54 am

you just don't see the results cause the entire while loop is done in one frame...
User avatar
Error
InsideQC Staff
 
Posts: 865
Joined: Fri Nov 05, 2004 5:15 am
Location: VA, USA


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest