Author Topic: (no subject)  (Read 2944 times)

Mark of the Dragon

  • Member
  • *
  • Posts: 1658
    • View Profile
    • http://www.geocities.com/zeroentity01/
(no subject)
« 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?
« Last Edit: December 31, 1969, 06:00:00 PM by Mark of the Dragon »
<center>
Roy Mustang



Yeah...that sounds like me <_<

<center>
You were born in the land of Warrior Pride. You live to fight, you have a strong spirit, courage and bravery. Strong lord! Unsheath thy sword, rush into war and strip the enemy of his flesh down to the core.


Umm...yeah

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #1 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
« Last Edit: December 31, 1969, 06:00:00 PM by Colin »
— Colin

Mark of the Dragon

  • Member
  • *
  • Posts: 1658
    • View Profile
    • http://www.geocities.com/zeroentity01/
(no subject)
« Reply #2 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.
« Last Edit: December 31, 1969, 06:00:00 PM by Mark of the Dragon »
<center>
Roy Mustang



Yeah...that sounds like me <_<

<center>
You were born in the land of Warrior Pride. You live to fight, you have a strong spirit, courage and bravery. Strong lord! Unsheath thy sword, rush into war and strip the enemy of his flesh down to the core.


Umm...yeah

DarkElite

  • Member
  • *
  • Posts: 1452
    • View Profile
    • http://cryosoft.mysticsoftware.net/Home.html
(no subject)
« Reply #3 on: May 30, 2004, 11:04:15 AM »
this stuff looks useful. i might try and learn some!  Razz
« Last Edit: December 31, 1969, 06:00:00 PM by DarkElite »
DarkElite

Dei vobem omniam proditiverunt.  Iam vobis quis deposcibitis sacrificium rersum vitae est!

Mark of the Dragon

  • Member
  • *
  • Posts: 1658
    • View Profile
    • http://www.geocities.com/zeroentity01/
(no subject)
« Reply #4 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?
« Last Edit: December 31, 1969, 06:00:00 PM by Mark of the Dragon »
<center>
Roy Mustang



Yeah...that sounds like me <_<

<center>
You were born in the land of Warrior Pride. You live to fight, you have a strong spirit, courage and bravery. Strong lord! Unsheath thy sword, rush into war and strip the enemy of his flesh down to the core.


Umm...yeah

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #5 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.
« Last Edit: December 31, 1969, 06:00:00 PM by Colin »
— Colin

Spyder

  • Member
  • *
  • Posts: 1695
    • View Profile
    • http://www.mysticsoftware.net
(no subject)
« Reply #6 on: June 01, 2004, 07:27:16 PM »
VB is f*ing weird... :blink:
« Last Edit: December 31, 1969, 06:00:00 PM by Spyder »

Mark of the Dragon

  • Member
  • *
  • Posts: 1658
    • View Profile
    • http://www.geocities.com/zeroentity01/
(no subject)
« Reply #7 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!
« Last Edit: December 31, 1969, 06:00:00 PM by Mark of the Dragon »
<center>
Roy Mustang



Yeah...that sounds like me <_<

<center>
You were born in the land of Warrior Pride. You live to fight, you have a strong spirit, courage and bravery. Strong lord! Unsheath thy sword, rush into war and strip the enemy of his flesh down to the core.


Umm...yeah

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #8 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.
« Last Edit: December 31, 1969, 06:00:00 PM by Colin »
— Colin

Mark of the Dragon

  • Member
  • *
  • Posts: 1658
    • View Profile
    • http://www.geocities.com/zeroentity01/
(no subject)
« Reply #9 on: June 01, 2004, 10:26:04 PM »
Well, I haven't learned classes in VB yet.
« Last Edit: December 31, 1969, 06:00:00 PM by Mark of the Dragon »
<center>
Roy Mustang



Yeah...that sounds like me <_<

<center>
You were born in the land of Warrior Pride. You live to fight, you have a strong spirit, courage and bravery. Strong lord! Unsheath thy sword, rush into war and strip the enemy of his flesh down to the core.


Umm...yeah

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #10 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
« Last Edit: December 31, 1969, 06:00:00 PM by Colin »
— Colin

Mark of the Dragon

  • Member
  • *
  • Posts: 1658
    • View Profile
    • http://www.geocities.com/zeroentity01/
(no subject)
« Reply #11 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.
« Last Edit: December 31, 1969, 06:00:00 PM by Mark of the Dragon »
<center>
Roy Mustang



Yeah...that sounds like me <_<

<center>
You were born in the land of Warrior Pride. You live to fight, you have a strong spirit, courage and bravery. Strong lord! Unsheath thy sword, rush into war and strip the enemy of his flesh down to the core.


Umm...yeah

AlienDude

  • Member
  • *
  • Posts: 605
    • View Profile
    • http://www.taralax.com
(no subject)
« Reply #12 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.
« Last Edit: June 07, 2004, 10:07:08 AM by AlienDude »
Quote
May your star always be good to you and may your travels be swift.
 
- Traveller Farewell
(adapted from the Necroscope series by Brian Lumley)

Taralax Studios BEING REBUILT GENOME BY GENOME! \n\t\t\t\t\t\t\t\t\t
<' + '/div>\n\t\t\t\t\t\t\t\t\t