Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Stuck with MS scripting control
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

VBBR
Moderator

Brazil
617 Posts

Posted - Jan 31 2005 :  11:24:25 AM  Show Profile  Reply with Quote
So I decided to write a scripted cut-scene engine using the MS scripting control. It was all going well until I got to the 'sleep' function.

Basically what SLEEP does is halt the execution of the script (not the program) for a given number of milliseconds. To achieve that, I parse the entire script and run one line at a time, and before running each line I check if the script is sleeping, and if it is, I pass execution and the app keeps looping until the sleeping time has passed; I then run the next line.

It was working beautifully until I tried a Do loop. Then I noticed how screwed the system was. If I only run a line at a time I can't use multi-line statements like Do, big If, With, etc (which makes the engine too little powerful). And if I execute the entire script at once, I can't use the sleep function at all! (even if I run just the entire Do, If, With, whatever structure at once, I won't be able to sleep inside it)

So, any ideas on how to solve that?

Whatever. Who knows...

Edited by - VBBR on Jan 31 2005 11:26:32 AM

VBBR
Moderator

Brazil
617 Posts

Posted - Jan 31 2005 :  1:51:25 PM  Show Profile  Reply with Quote
Never mind, I found a way to do this. I can post the solution if anyone's interested.


Whatever. Who knows...
Go to Top of Page

sdw
Warrior

USA
160 Posts

Posted - Feb 02 2005 :  9:58:38 PM  Show Profile  Visit sdw's Homepage  Click to see sdw's MSN Messenger address  Reply with Quote
We're interested. Just post it already :D
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Feb 03 2005 :  05:11:53 AM  Show Profile  Reply with Quote
Hm.... Something as simple as running the entire script at once and making the sleep function as follows:

Do While slpTime < slpTotal  
    DoMainLoopStuff  
    slpTime = slpTime + FrameTime  
Loop

So basically I've moved the main application loop to the Sleep sub. Not very clean, but it works.

Whatever. Who knows...

Edited by - VBBR on Feb 03 2005 05:12:16 AM
Go to Top of Page

Eric Coleman
Gladiator

USA
811 Posts

Posted - Feb 04 2005 :  4:34:53 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
Another way is to pre-process your scripts for a sleep command.

For Example, assume you have the following script ...
  
Sub MySub()  
    DoSomething()  
    Sleep 5  
    DoSomething()  
    Sleep 3  
    DoSomething()  
End Sub
  


Before you load the script into the MS ScriptControl, search for the Sleep function and break the code into diferent pieces. The previous sub would look something like this...

  
Sub MySub()  
    DoSomething()  
    Sleep 5  
End Sub
Sub MySub_part1()  
    DoSomething()  
    Sleep 3  
End Sub
Sub MySub_part2()  
    DoSomething()  
End Sub
  


The next step is to replace the "sleep" command with a global function that's part of your game. The function is essentially a timer and it takes 2 paramters, the time to wait from the original "sleep" command and also the next function to call. The end result of the script would look something like this:

  
Sub MySub()  
    DoSomething()  
    'Sleep 5  
    EngineSleep 5, "MySub_part1"  
End Sub
Sub MySub_part1()  
    DoSomething()  
    'Sleep 3  
    EngineSleep 3, "MySub_part2"  
End Sub
Sub MySub_part2()  
    DoSomething()  
End Sub
  


The "EngineSleep" command simply starts a timer in your program (it doesn't have to be a Timer object, you can keep track of elapsed time however you want) and after the time has elapsed it calls the next part of the sub. This prevents you from running out of stack space in the event that your "DoMainLoopStuff" executes more game code that calls a script with another sleep function. You would end up with something like this...

  
MainLoop  
> Call Script  
    > Sleep  
       > DoMainLoopStuff  
          > Call Script  
             > Sleep  
                > DoMainLoopStuff  
                   > Call Script....  
  


This method won't work for functions though. However, having a "sleep" command in a function could lead to some really nasty bugs in your game. A function A that calls another function B that has a sleep command that you forgot about can make you wonder why function A takes so long to execute.
Go to Top of Page

VBBR
Moderator

Brazil
617 Posts

Posted - Feb 04 2005 :  6:43:51 PM  Show Profile  Reply with Quote
Hm... If this was the case I'd just execute the script line by line. But the problem is if I need to call the Sleep function inside a nested statement like a Do, If, Select Case, With, etc.

I'll be careful not to let another script execute while the engine is sleeping though. (return an error if something tries to do this; anyway is doesn't look like someone would do it...)

Whatever. Who knows...
Go to Top of Page

hotrodx
Squire

43 Posts

Posted - Feb 20 2005 :  10:12:43 PM  Show Profile  Reply with Quote
Here's my sub:


Sub WorkHard()

If Coffee = 0 then Sleep 1000

End Sub

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.17 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.