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

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
VBBR Posted - Jan 31 2005 : 11:24:25 AM
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?
6   L A T E S T    R E P L I E S    (Newest First)
hotrodx Posted - Feb 20 2005 : 10:12:43 PM
Here's my sub:


Sub WorkHard()

If Coffee = 0 then Sleep 1000

End Sub
VBBR Posted - Feb 04 2005 : 6:43:51 PM
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...)
Eric Coleman Posted - Feb 04 2005 : 4:34:53 PM
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.
VBBR Posted - Feb 03 2005 : 05:11:53 AM
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.
sdw Posted - Feb 02 2005 : 9:58:38 PM
We're interested. Just post it already :D
VBBR Posted - Jan 31 2005 : 1:51:25 PM
Never mind, I found a way to do this. I can post the solution if anyone's interested.

VBGamer © Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000

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