Page 1 of 1

Problem with incrementation

Posted: Sun Dec 11, 2016 3:32 pm
by Ar-S
Hello, i'm using SB 2 demo.
I'm trying to convert a pure basic program but i have a problem to add +1 to some values with a timer. I do not understand why.

thanks for helping.

Code: Select all


Declare TimerEvents()
Declare GO()

Global Launch, NbrDes, Count

;- INIT
  NbrDes = 3
  Launch = #True
  Count = 0
  ;--------
  
Procedure TimerEvents()
  Protected X, Count

  If Launch = #True
    Count+1

    X + 128
    ;- TEST -----------------------
    Debug "X : " + X
    Debug "Count : " + Count
    ;- EndTest ---------------------
    
    If Count = NbrDes
      X = 0
      Count = 0
      Launch = #False
      Debug "This is the end, my only friend, the end."
    EndIf
    
  EndIf
EndProcedure


Procedure GO()

  OpenWindow(0, #PB_Ignore, #PB_Ignore, 128*3, 128+50,"Virtual Dices",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  AddWindowTimer(0,1,300)

  BindEvent(#PB_Event_Timer, @TimerEvents(),0)

EndProcedure



GO()

Re: Problem with incrementation

Posted: Mon Dec 12, 2016 6:13 am
by Fred
May be you should not protect the 'count' variable

Code: Select all

Protected X, Count

Re: Problem with incrementation

Posted: Mon Dec 12, 2016 11:45 am
by Ar-S
:oops: OK thanks