Mystic Software Forums

Miscellaneous => General Off-Topic => Topic started by: Mark of the Dragon on May 29, 2004, 07:37:12 PM

Title: (no subject)
Post 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?
Title: (no subject)
Post by: Colin on May 29, 2004, 09:09:06 PM
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:

Code: [Select]
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...

Code: [Select]
Timer.Enabled = False
And on again (at exactly the same spot)...

Code: [Select]
Timer.Enabled = True
Title: (no subject)
Post by: Mark of the Dragon on May 29, 2004, 09:23:14 PM
Thanks, man. I'll probably go and try this tomorrow morning, when my brain can process code again, lol.
Title: (no subject)
Post by: DarkElite on May 30, 2004, 11:04:15 AM
this stuff looks useful. i might try and learn some!  Razz
Title: (no subject)
Post by: Mark of the Dragon on May 31, 2004, 05:27:26 PM
Ok, this is the full code of what I have so far on that form:

Code: [Select]
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?
Title: (no subject)
Post by: Colin on June 01, 2004, 07:23:43 PM
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.
Title: (no subject)
Post by: Spyder on June 01, 2004, 07:27:16 PM
VB is f*ing weird... :blink:
Title: (no subject)
Post by: Mark of the Dragon on June 01, 2004, 09:27:26 PM
*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!
Title: (no subject)
Post by: Colin on June 01, 2004, 09:37:04 PM
Did I tell you just how horribly wrong you are programming an RPG engine? Use a class for each direction.
Title: (no subject)
Post by: Mark of the Dragon on June 01, 2004, 10:26:04 PM
Well, I haven't learned classes in VB yet.
Title: (no subject)
Post by: Colin on June 02, 2004, 03:03:17 PM
Code: [Select]
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
Title: (no subject)
Post by: Mark of the Dragon on June 04, 2004, 07:07:31 PM
Thanks for the help; I'll keep everyone posted. Keep in mind, this is still a learning experience for me.
Title: (no subject)
Post by: AlienDude on June 07, 2004, 10:05:12 AM
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.
Title: (no subject)
Post by: AlienDude on January 21, 2005, 10:30:32 AM
sorry to take this dusty tome off the shelf but are there any updates on MOTD's engine?  I am very curious...



mmmmm honeyhut