What could be causing my destinationVariable to not update in my timer program?

AI Thread Summary
The discussion revolves around a programming issue where the variable "destinationVariable" is not updating as expected within a function. The user is attempting to increment this variable based on a timer condition but is not seeing any results. The code structure includes a main subroutine that calls another subroutine, "myfunction," which uses a static variable "myClock" to track time. The key point raised is that the conditional check for incrementing "destinationVariable" may not be met because the timer values are being evaluated too closely together, making it unlikely for the condition to evaluate as true unless the program is interrupted. This suggests that a continuous loop or a different approach may be necessary to ensure that the condition can be met reliably.
angelspikes
Messages
10
Reaction score
0
I've debugged and run my program without seeing any results from my "destinationVariable".
What could be wrong?

sub main()

call myfunction()

end sub

sub myfunction()

static myClock As Single

myClock = timer

if (timer - myClock) > 100 Then
destinationVariable += 1 // This variable is linked to this script
End If

End Sub

// I want the function to run in a loop, but I guess I don't need to use the do loop function to make that happen?
 
Technology news on Phys.org
angelspikes said:
myClock = timer
if (timer - myClock) > 100 Then

Since these lines execute right after each other, I doubt that the "if" test will ever be true unless the program gets interrupted between the two statements. That would be "rare". It may happen occasionally if you put this in a hard loop and run it continuously, but the odds on anyone run are very small.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top