Results 1 to 7 of 7

Thread: More than one line of code at a time?

  1. #1

    Thread Starter
    Lively Member VBNubcake's Avatar
    Join Date
    Feb 2008
    Location
    Caledon, Ontario, Canada
    Posts
    80

    More than one line of code at a time?

    Is it possible to have vb read and execute code from two different subs at the SAME time?

    By that i dont mean:
    execute first sub
    first sub finishes
    Call second sub
    execute second sub

    I mean:
    execute first sub & execute second sub (at the same time)

    What am I trying to do?
    -I'm working on an RPG, which includes a "battle form".
    -In the "battle form": there are multiple monsters
    -The monsters are being animated by using .Render
    -Each monster animation has its own public sub
    -Currently, one monster animates at a time (because VB only reads one sub at a time....one line at a time)

    Potential Solution
    -Merge all the subs into one giant sub (this will take alot of recoding, new variables, new calculations, new user-defined types...work involved...might not even work properly)

    If there is an API or anything else that can solve my problem, it would make my solution alot easier.

    any ideas?

    anyways, heres some code in my project, maybe this will help you guys understand what im trying to do:


    Code:
    '======================================================
    '====================SLIME_STANCE SUB==================
    '======================================================
    Public Sub SLIME_STANCE()
    'Draw FIRST frame
    picEnemy.Cls
    With BI.Images.BattleZone
        .Render picEnemy.hDC, 0, 0, 600, 400, ScaleX(10, vbPixels, vbHimetric), ScaleY(450, vbPixels, vbHimetric), ScaleX(600, vbPixels, vbHimetric), ScaleY(-400, vbPixels, vbHimetric), 0&
    End With
    With BI.ES.SLIME_STANCE(0)
        .Render picEnemy.hDC, 0, 0, ScaleX(.Width, vbHimetric, vbPixels), ScaleY(.Height, vbHimetric, vbPixels), 0, .Height, .Width, -.Height, 0&
    End With
    picEnemy.Refresh
    
    'Wait 50 Milliseconds
    Sleep 50
    'Draw SECOND frame
    picEnemy.Cls
    With BI.Images.BattleZone
        .Render picEnemy.hDC, 0, 0, 600, 400, ScaleX(10, vbPixels, vbHimetric), ScaleY(450, vbPixels, vbHimetric), ScaleX(600, vbPixels, vbHimetric), ScaleY(-400, vbPixels, vbHimetric), 0&
    End With
    With BI.ES.SLIME_STANCE(1)
        .Render picEnemy.hDC, 0, 0, ScaleX(.Width, vbHimetric, vbPixels), ScaleY(.Height, vbHimetric, vbPixels), 0, .Height, .Width, -.Height, 0&
    End With
    picEnemy.Refresh
    
    'Wait 50 Milliseconds
    Sleep 50
    'Draw THIRD frame
    picEnemy.Cls
    With BI.Images.BattleZone
        .Render picEnemy.hDC, 0, 0, 600, 400, ScaleX(10, vbPixels, vbHimetric), ScaleY(450, vbPixels, vbHimetric), ScaleX(600, vbPixels, vbHimetric), ScaleY(-400, vbPixels, vbHimetric), 0&
    End With
    With BI.ES.SLIME_STANCE(2)
        .Render picEnemy.hDC, 0, 0, ScaleX(.Width, vbHimetric, vbPixels), ScaleY(.Height, vbHimetric, vbPixels), 0, .Height, .Width, -.Height, 0&
    End With
    '======================================================
    '================END OF SLIME_STANCE SUB===============
    '======================================================
    This is a Public Sub called "SLIME_STANCE".
    This sub actually has alot more code (goes upto "Draw ELEVENTH frame") but the concept is still the same
    This Sub handles the animation of a "monster" called a "Slime" using the sleep API as well as the .Render to cycle sprites
    Spites for the Slime are stored in BI.ES.SLIME_STANCE()
    Once the sub is finished executing, it is then recalled to continue the animation

    My problem is:
    I need to execute "SLIME_STANCE" while a public sub called "CHARACTER_ATTACK" is also being executed. This allows my game to have the monster and the player's character animating at the same time.

    Right now when i call "CHARACTER_ATTACK", i have to wait for the "Slime" to stop animating (I have to wait for "SLIME_STANCE" to finish executing). Once the "Slime" stops animating, "CHARACTER_ATTACK" then begins to execute, and the player then animates. Once this sub is finished executing, "SLIME_STANCE" begins executing again (The "Slime" starts to animate again). What I need is the "Slime" to continue animating while the character attacks the "slime"
    Last edited by VBNubcake; Apr 30th, 2008 at 03:17 PM.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: More than one line of code at a time?

    This is called multi-threading...

    You can't call 2 subs simultaneously, but you can have one execute while the other one is working.

    There is a multi-threading example in the VB6 CodeBank. There is also this one, which I've used in the past:
    http://pscode.com/vb/scripts/ShowCod...26900&lngWId=1

    There may be a better solution to your problem than multi-threading, but that's hard to say without seeing the code and knowing how you're rendering.

    A timer might even be a better option, but it's hard to say not knowing what code you're using...

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: More than one line of code at a time?

    Create an ActiveX EXE then launch multiple object that have the same code but can execute differently.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: More than one line of code at a time?

    Usually in games there is a repeating loop;
    - perform house keeping or do relevant processing, e.g. update info, calculations, stats, etc)
    - update graphics
    - retrieve user input
    - do additional processing before loop repeat if any
    - repeat loop

    Did you design accordingly? Or are you solely control event driven, e.g. button click.

  5. #5

    Thread Starter
    Lively Member VBNubcake's Avatar
    Join Date
    Feb 2008
    Location
    Caledon, Ontario, Canada
    Posts
    80

    Re: More than one line of code at a time?

    Quote Originally Posted by leinad31
    Usually in games there is a repeating loop;
    - perform house keeping or do relevant processing, e.g. update info, calculations, stats, etc)
    - update graphics
    - retrieve user input
    - do additional processing before loop repeat if any
    - repeat loop

    Did you design accordingly? Or are you solely control event driven, e.g. button click.
    i designed accordingly

  6. #6

    Thread Starter
    Lively Member VBNubcake's Avatar
    Join Date
    Feb 2008
    Location
    Caledon, Ontario, Canada
    Posts
    80

    Re: More than one line of code at a time?

    Quote Originally Posted by DigiRev
    This is called multi-threading...

    You can't call 2 subs simultaneously, but you can have one execute while the other one is working.

    There is a multi-threading example in the VB6 CodeBank. There is also this one, which I've used in the past:
    http://pscode.com/vb/scripts/ShowCod...26900&lngWId=1

    There may be a better solution to your problem than multi-threading, but that's hard to say without seeing the code and knowing how you're rendering.

    A timer might even be a better option, but it's hard to say not knowing what code you're using...
    I looked at the link you referred me to, it looks like it should work, i'm gonna give it a shot..i'll keep you guys posted

    Still open to suggestions, should they arise

  7. #7

    Thread Starter
    Lively Member VBNubcake's Avatar
    Join Date
    Feb 2008
    Location
    Caledon, Ontario, Canada
    Posts
    80

    Re: More than one line of code at a time?

    Yeah I gave that tutorial a shot, it ended up re-directing me to "newer code" a couple times, i dled their attatchments and tried running the code...i got some runtime errors, couldnt find something in the library...the tutorial itself was a bit confusing (probably just me being VB illiterate), if anyone has a Fool proof tutorial on multi threading please please please send it this way
    Last edited by VBNubcake; Apr 30th, 2008 at 03:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width