Results 1 to 9 of 9

Thread: Control arrays have only one dimension =(

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    25

    Question

    In my mud game (BeMUD if anyone remembers) the NPCs characters are referred as two-dimensional array (i.e Npc(1,3).Name="Orc")). Now I want to create timers array especially for the NPCs (Each NPC should have a private timer). However I can make the timers array only with one dimension thus I cannon directly refer NPCs from the timers.
    Someone has an idea to how to handle this problem?
    VitalyB - VB6 Pro

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Don't use more than one timer! If your game is timecritical you could as well make it run in a infinite loop with gettickcount managing the timing. Actually i would recommend the second for you since it might be real confusing to control several asyncronous timer events. What are you using a two dimensional array for to have npc's? might be i'm missing something important.

    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    25

    Timers are a must (it seems)

    Eventually I already have timer for every PC player as well. Timers are needed for dealyed actions. For example PC wants to attack another PC so he writes:
    hit Ace
    Then he sees:
    You're aiming... (Or something like that)
    After some time he sees:
    You land the blow on...

    When a player does a delayed command only half of it is executed, then the timer of the player is turned on for the delay, when the delay is over the timer of the player is turned off and the command proceeds.

    You get the idea. As I see it now there is no other way to do this delay and even though I don't like the way I am using the timers it is the only way.

    Basically NPCs would need something like that too.
    VitalyB - VB6 Pro

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    You can use an endless loop like this:
    Code:
    Form_Load
    Do
        'get the time
        Time = GetTickCount
        'do something
        If Time = 5 Then
            Msgbox ":-)"
        End If
        'don't freeze the system
        DoEvents
    Loop
    End Sub
    Note that the code doesn't work, it just some example. Use GetTickCount for the delay.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    25
    Right, that was my first my choise the following problem occured with that way (Do DoEvents Loop).

    See this example:
    Player A (PC) presses hit and actually enters the delay loop. Now before the time delay is over player B presses hit too. Because of the DoEvents it makes the command work and the command is being processed now player B enters to the same loop as well which means that player A won't be able to hit until player B hits. The loop of player A hit command doesn't process because there is another loop going on for player B.

    Hope I said it right *crosses his fingers*
    VitalyB - VB6 Pro

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Create a collection, holding the tasks and when (milliseconds) they're needed to execute. So, then loop processes all tasks in the collection.
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    25
    Collection like the one you said is a possible solution however testing the collection every time it is in the Do loop is being even more messy than doing the delay timer.

    I don't seem to understand what's so wrong (But the two dimensional part :|) in using timers?
    VitalyB - VB6 Pro

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    The whole idea with the game loop is that id doesn't initialize every time, it's running all the time and waiting for next thing to do, while drawing the grapphics, reading keyboard, mouse or whatever. So if you still are working with events, just set flags on and off, otherways you should use a directinput device or enumerating all keys with getasynckeystate.

    Now as oetje said, you make a queue of tasks, which have assigned time when they will fire and be removed from the list, that is easiest done with linked lists like collections but can also be done faster with arrays if you just optimize it once a while or have another array storing the free spaces, like freefile does for filesystem in vb.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Posts
    25
    Seems that I had to explain the concept first.
    My game is an internet multiplayer text game(=Mud) and it is critical to the game that delays will happen and won't interfare(sp) each other.

    A queue of delays is not possible simply because they're not supposed to be queued in the first place. Player A and Player B are supposed to be able to hit together...

    Am I missing something?
    VitalyB - VB6 Pro

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