|
Post by Andy on Mar 19, 2005 20:11:39 GMT
I'm wondering if anyone can help me figuire out how to run 2 part program in QBasic where part 1 runs in the background and part 2 in the foreground. Here's a simplified example to illustrate my question: Let's say part 1 is to print "Hello", wait 2 seconds, then loop continuously until the program stops. Let's say part 2 is to print "New" after the program has been running for 30 seconds, wait 10 seconds, then print "York". Part 1 would not be affected by Part 2, and would keep running during and after execution of Part 2. Someone told me this is done using interrupts, but I don't know how that would work. Can anyone explain it to me (or better yet, send some sample code?). Thanks very much.
|
|
|
Post by Ildûrest on Mar 19, 2005 23:33:47 GMT
Firstly, be aware that two programs never run at once. The operating system (such as Windows) just lets one run for a bit, then pauses it and lets another one run for a bit, pauses it, and lets another one run for a bit, and so on. I doubt the "someone" who told you about interrupts knew much about them himself, because sure it's possible, but it's very difficult unless you want to dig around for addresses of the assembly code of your program, and there's a much easier way, which is to keep track of where both things are at. (I will say however, interrupts can be very useful, and for one thing let you access the mouse in QB. I can give you more information if you want.) Now, the forums quell indentation so instead I've hosted an example over here www.autopack.com/aleks/EXAMPLE.BASTIMER, if you didn't know, returns the number of seconds elapsed since midnight (but it has a decimal portion, e.g. 623.48 seconds) and it's great for making delays and the like. Anyway, the example I put has two things running running together and then when you press a key, "Hello" finishes moving, and "New York" finishes off if it is incomplete. Now when you want to make things like this, the key is to make a routine that advances a process by one step. Instead of using a FOR-NEXT you may need to use a counter variable and add 1 to it each time the routine runs once, so it can take up where it left off next time. Good luck. If you want more help just ask.
|
|
ADG01
New Member
Posts: 3
|
Post by ADG01 on Mar 20, 2005 2:16:51 GMT
Thanks!
|
|
|
Post by ave libre on Mar 20, 2005 5:28:55 GMT
i would try to use the windows capabilities, using SHELL with START from the first program
SHELL "START SECOND.exe"
or maybe
SHELL "START qbasic/run SECOND.bas"
when you use START the quickbasic activates a second part or program and returns immediately to the Basic, the windows take the second part or program and runs it while the Basic continues its own part or program
|
|
|
Post by Ildûrest on Mar 21, 2005 10:57:21 GMT
I wouldn't in this case, as you can't see both programs at once.
And I think some (or all) versions of Windows pause a DOS program if it is not the Active Window or fullscreen.
It may help on some occasions though. It certainly is useful if you want to use a slave program to do something that QB can't normally do.
But you definitely can't make a game with multiple enemies all moving at once work using START.
|
|
ADG01
New Member
Posts: 3
|
Post by ADG01 on Mar 27, 2005 4:25:31 GMT
Thanks again for the help. I've studied the example program, and I think I can apply those concepts to my project. One refinement that would help a lot - the way it is now written, there is one letter of New York for each time Hello prints. What's the simplest way to have New York do its thing for a while, and then have hello pop up after 10 seconds, again after another 5 seconds, and then no more Hello. Meanwhile, New York keeps going.
|
|
|
Post by Ildûrest on Mar 27, 2005 5:22:23 GMT
Simple enough... (although there's lots of other methods to this one): have a counter variable that you use in a SELECT CASE or some similar thing, that makes HelloTime! be set to TIMER + 10 the first time around, TIMER + 5 the next time around, and 86500 the next time. (TIMER will never get this high)
Alternatively, you could have two or three DO-LOOP stages, all of them containing NEW YORK but otherwise being adjusted for the HELLO bit.
You may also get some benefits by putting some of this stuff in a SUB or GOSUB-RETURN.
It's really up to you, and a lot of it depends on your decision and also what you're using this for.
Good luck!
|
|
ADG01
New Member
Posts: 3
|
Post by ADG01 on Mar 28, 2005 0:20:18 GMT
Thanks again. I might use a combination of those ideas in my application. I might actually start some of the sequences by hitting a function key with a gosub, and have the subroutine set a timer that would trigger another gosub. That way I can control when different things start but they stop automatically. Anyway, thanks for the ideas.
|
|
|
Post by ohomujumukiza on Nov 8, 2019 22:29:48 GMT
|
|