[Solved]Setting up a timer

Understanding the language, error messages, etc.

Re: Setting up a timer

Postby ajsb113 » Thu Oct 23, 2014 2:27 pm

Here's my code for the game thus far. I'm sorry about how unorganized/messy it is, it's a work in progress. Thanks for taking a look at it!
Attachments
Maruino.zip
(2.65 KiB) Downloaded 222 times
User avatar
ajsb113
 
Posts: 45
Joined: Tue Jun 24, 2014 4:47 am
Location: Illinois, United States

Re: Setting up a timer

Postby Zoglu » Thu Oct 23, 2014 4:18 pm

I got your timer to work by commenting out your updatePlayer call (file "Maruino", line 44). The problem might come from this !

EDIT : here is what you have at the beginning of your updatePlayer function :
Code: Select all
  if(time = 0){
    startGame();
  }

If I remember correctly, if(time = 0) doesn't check if time equals to 0, but instead changes time to 0 and returns true. You should try to change it to if(time == 0).
Zoglu
 
Posts: 26
Joined: Thu Oct 09, 2014 5:13 pm

Re: Setting up a timer

Postby ajsb113 » Fri Oct 24, 2014 1:55 pm

Thank you! I knew it was going to be something as stupid as a missing = sign :roll: . Thanks for checking it out! :D
User avatar
ajsb113
 
Posts: 45
Joined: Tue Jun 24, 2014 4:47 am
Location: Illinois, United States

Re: [Solved]Setting up a timer

Postby Myndale » Fri Oct 24, 2014 10:07 pm

There's an interesting trick in the book Writing Secure Code (I think) in which you write these types of statements with the constant on the left hand side of the equation i.e. "if (0==time) ....". Reason being that constants cannot be assigned to, so if you do accidentally forget an equal sign the compiler will throw up an error.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: [Solved]Setting up a timer

Postby rodot » Sat Oct 25, 2014 7:33 am

Myndale wrote:There's an interesting trick in the book Writing Secure Code (I think) in which you write these types of statements with the constant on the left hand side of the equation i.e. "if (0==time) ....". Reason being that constants cannot be assigned to, so if you do accidentally forget an equal sign the compiler will throw up an error.


Nice tip, thanks! :)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Previous

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 4 guests