Problem with if statement

przemek

New member
Joined
Sep 18, 2017
Messages
62
Thank you martin. You made wood add 1 every 20 sec not 50. Thank you both.
 

przemek

New member
Joined
Sep 18, 2017
Messages
62
Code:
Import mojo
Class CGame Extends App
    Field lastTick:Int
    Field elapsedTimeInSecSinceLastWoodCount:Int
    Field secs:Int
    Field mins:Int
    Field hrs:Int
    Field dys:Int
    Field wood:Int
    Method OnCreate:Int()
        SetUpdateRate(0)
        lastTick = Millisecs()
        elapsedTimeInSecSinceLastWoodCount = 0
        wood = 0
        Return 0
    End Method
    Method OnUpdate:Int()
        Local dt:Int = Millisecs()-lastTick
        If dt>1000
            lastTick = Millisecs()
            secs += 1
            elapsedTimeInSecSinceLastWoodCount += 1
        Endif
        If secs > 59 Then
            secs = 0
            mins +=1
            If mins > 59 Then
                mins = 0
                hrs +=1
                If hrs > 23 Then
                    hrs = 0
                    dys += 1
                Endif
            Endif
        Endif
          If elapsedTimeInSecSinceLastWoodCount >= 20
              wood += 1
              elapsedTimeInSecSinceLastWoodCount = 0
          End If
        Return 0
    End Method
    Method OnRender:Int()
        Cls
        DrawText("Sec: "+secs, 570, 10)
        DrawText("Min: "+mins, 510, 10)
        DrawText("Hour: "+hrs, 440, 10)
        DrawText("Day: "+dys, 380, 10)''''''''''''''''
        DrawText("Wood: "+wood, 100, 100)
        Return 0
  
    End Method
End Class
Function Main:Int()
    New CGame()
    Return 0
End Function
 

Gerry Quinn

Active member
Tutorial Author
Joined
Jun 24, 2017
Messages
153
OK, I got a post when you replied to mine, but I see the conversation has moved on! (Yes, by the way, I put my stuff as a method to be called during OnUpdate(), but you could just put the body of code into OnUpdate() if you prefer.)

Pro tip: the 'Print' statement is an unsophisticated way to debug, but once upon a time it was all we had, and nowadays it is still quite useful. If wood is supposed to change periodically, a 'Print "Wood: " + wood' statement near where it's supposed to be tested for changing will tell you whether the test is being reached, and/or whether it works as it's supposed to.
 
Last edited:

przemek

New member
Joined
Sep 18, 2017
Messages
62
Now, I will add boarders for the character so the character cant go past them ( I will put resources and time there). Now Im working out how to change characters pose whenever i go left/right/up/down.
 
Top Bottom