Mystic Software Forums
Miscellaneous => General Off-Topic => Topic started by: Mark of the Dragon on May 29, 2004, 07:37:12 PM
-
Alright, I'm trying to get sprite movement down for this RPG I'm working on for a Visual Basic class that I'm taking, and I can't get the timer to stop looping unless I shut it down completely, and I can't find a way to get the timer to start up again when I want the movement sub-procedure to be called again.
Tips, please?
-
Realistically you should be using a class with a member variable of type Timer. But since you probably don't know a thing about classes and I haven't seen your code that won't do much good.
For now, set the timer delay to 1 and use THIS code:
dim lngTimerCount as long
Sub Timer_OnTimer()
const TIMER_SECONDS as integer = 5 'or whatever
lngTimerCount = lngTimerCount + 1
If lngTimerCount / 100 = TIMER_SECONDS
lngTimerCount = 0
Else
exit sub
End If
'Code to run when timer is called...
'Blah, blah. blah
End Sub
To turn the timer off...
Timer.Enabled = False
And on again (at exactly the same spot)...
Timer.Enabled = True
-
Thanks, man. I'll probably go and try this tomorrow morning, when my brain can process code again, lol.
-
this stuff looks useful. i might try and learn some! Razz
-
Ok, this is the full code of what I have so far on that form:
Private intTop As Integer
Private intLeft As Integer
Private intTimesRun As Integer
Private intRun As Integer
Private intReady As Integer
Private Sub Form_Load()
intLeft = 1
intTop = 60
Dim lngTimerCount As Long
Call KevinRight
End Sub
Private Sub KevinRight()
tmrKevinRight.Enabled = True
End Sub
Private Function GetImage(n As String) As String
GetImage = "d:\IMAGES\" & n
End Function
Private Sub tmrKevinRight_Timer()
Const TIMER_SECONDS As Integer = 5 'or whatever
lngTimerCount = lngTimerCount + 1
If lngTimerCount / 100 = TIMER_SECONDS Then
lngTimerCount = 0
Else
Exit Sub
End If
Dim intPixel As Integer
intPixel = 1
Do
picKevin.Move 1
intPixel = intPixel + 1
Loop While intPixel < 32
End Sub
It doesn't work at all. Any suggestions?
-
Well, not to offend you, but that code is rather scarey.
However, the problem you're thinking of is the fact that you declared lngTimerCount INSIDE Form_Load. That makes it "local" to Form_Load. In other words, each "instance" of Form_Load gets its own copy of it. Anything outside of Form_Load doesn't get it at all! Razz
Do:
Dim lngTimerCount As Long
AT THE TOP OF THE FORM.
Hope that helps.
-
VB is f*ing weird... :blink:
-
*Cuts arm twice (yes, for real...not just saying it)*
Well (Editor: Censored)! Why didn't I see that before!? God I really am stupid!
-
Did I tell you just how horribly wrong you are programming an RPG engine? Use a class for each direction.
-
Well, I haven't learned classes in VB yet.
-
dim intTop As Integer
dim intLeft As Integer
dim intTimesRun As Integer
dim intRun As Integer
dim intReady As Integer
dim lngTimerCount As Long
Private Sub Form_Load()
intLeft = 1
intTop = 60
KevinRight
End Sub
Private Sub KevinRight()
tmrKevinRight.Enabled = True
End Sub
Private Function GetImage(n As String) As String
GetImage = "d:\IMAGES\" & n
End Function
Private Sub tmrKevinRight_Timer()
Const TIMER_SECONDS As Integer = 5 'or whatever
lngTimerCount = lngTimerCount + 1
If lngTimerCount / 100 = TIMER_SECONDS Then
lngTimerCount = 0
Else
Exit Sub
End If
Dim intPixel As Integer
for intPixel = 1 to 32
picKevin.Move 1
intPixel = intPixel + 1
next intPixel
End Sub
I've made a few slight modifications to your code. If you want to send me your whole project, I'll make it rather classy! Razz
-
Thanks for the help; I'll keep everyone posted. Keep in mind, this is still a learning experience for me.
-
Satan may be opening a HoneyHut so I may be able to do some coding. Razz
Why not make them Public Subs??
Yeah, it look like you'd have to set separate progs for dir or add a dir recognition sub function into the mix.
Make a more general verzion and place it in a module (so it can be called by other progs).
Took a basic Basic (he) class a couple of years ago. so Im not a total noob.
-
sorry to take this dusty tome off the shelf but are there any updates on MOTD's engine? I am very curious...
mmmmm honeyhut