Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

wait for song?

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
djfenix




Joined: 12 Mar 2003
Posts: 359

PostPosted: Fri Nov 23, 2007 1:02 pm    Post subject: wait for song? Reply with quote

There isn't any command for it, but I'm not sure if there's any way to get this done.

Just waiting for ticks seem highly unreliable, and the length of ticks change from computer to computer.

What i'm trying to do is have events cue on music. So i broke up the song into parts (essentially, the same song as two separate songs). So the camera would simply pan as long as it takes for the first part of the song, then the events would trigger once it gets into the second part.

So, what i was thinking of doing is using the computer's internal clock. I would first have to know the length of each song by minutes/seconds/milliseconds, then i would need to know the clocks current time. I would add the time of the song to the current time, and have the next song cue up when that time arrives along with the events to follow.

This is just my approach in my head right now, I'm not exactly sure if it'll work. But is there anything that may be simpler than this?
Back to top
View user's profile Send private message
Calehay
...yeah.
Class B Minstrel



Joined: 07 Jul 2004
Posts: 549

PostPosted: Fri Nov 23, 2007 4:57 pm    Post subject: Reply with quote

I tried your method, and the results were far from ideal. Since the smallest measurable unit of time is a second, you're going to deal with some very noticeable delays or early movements unless your music is 60 BPM and starts exactly at the tick of a second. (And also if your computer notates a new tick at the exact start of a second. On mine, it was pretty much spot on, but I don't know about others.)

Anyway, here's the script I used:

Code:

include, plotscr.hsd

plotscript, Walk Around to Music, begin
suspendplayer
    Variable(Arewedone)
    Variable(Heromoving)
    Variable(cursec)
    Variable(pastsec)
    Variable(cutcount)

   Arewedone := false
   Heromoving := false
   pastsec := system second

    Playsong (1)


    While(Arewedone == false) do
        (
            cursec := system second
   show value (cutcount)
                If(cursec <> past sec) Then
                   (
                        cutcount := cutcount+1
                        pastsec := system second
                    )
                 If (heromoving == false, and, cutcount << 15) Then
                    (
                        walk hero (0, north, 6)
                        heromoving := true
                    )
                 If (cutcount == 15) Then
                    (
                         heromoving := false
                    ) 
                 If (heromoving == false, and, cutcount << 60, and, cutcount >> 15) Then
                    (
                        walk hero (0, right, 6)
                        heromoving := true
                    )
                 If (cutcount == 60) Then
                    (
                        heromoving := false
                    )
                 If (heromoving == false, and, cutcount << 90, and, cutcount >> 60) Then
                    (
                        walkhero (0, down, 6)
         heromoving := true
                    )
                 If (cutcount == 90) Then
                    (
                        Arewedone := True
                    )
      wait (1)
        )
resumeplayer
end


The player moved at 0, 15, and 60 seconds. Because of an oversight I made as I am stupid, the player actually moved at 0, 16, and 61 seconds, and it was late but almost right. I changed the code so that it was a second earlier, but then it was too early.

If we could get the milliseconds in time, it wouldn't be a problem, but since the OHR runs in ticks of about 1/18 a second, I don't think it would be possible. Sad...

EDIT:
My script also suggests that you know that the movements fit in the time frame. I'm not sure how you could go around that.

EDIT 2:
One way to work around it is to time the movements just as if you were scoring a film. (Perhaps using something like CamStudio to record it would help in the timing) and compose/edit the song accordingly. You'd have a bit more control that way than trying to coax the OHR into fitting into the song.
_________________
Calehay
Back to top
View user's profile Send private message AIM Address
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Nov 23, 2007 5:17 pm    Post subject: Reply with quote

EDIT: Oh, Calehay posted before me. Note that ticks don't' fall at the beginning of seconds by default, and a single tick might be longer than a secod if the player suddenly maximises the window or something.

If your music is MP3/OGG, then you could import the pieces as sound effects instead, then you can use 'plot:sound is playing' to check if they're finished.

Otherwise, your idea's the approach Pepsi is using in Powerstick Man for timing textboxes to music. I added the milliseconds command in Ubersetzung for that purpose:

Code:
script, wait milliseconds, ms, begin
  variable (start)
  start := milliseconds
  while (milliseconds -- start << ms) do (wait)
end


Note: if you want more than one measured wait in the same scene, then you need to keep a global timer between them, otherwise it doesn't work well at all, as Pepsi and I found. Are you planning to sychronise the events in the second half to the music?
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Calehay
...yeah.
Class B Minstrel



Joined: 07 Jul 2004
Posts: 549

PostPosted: Fri Nov 23, 2007 5:45 pm    Post subject: Reply with quote

That milliseconds command isn't in the plotscript dictionary. So, does milliseconds report the current system millisecond, or the game play millisecond? Also, does it add milliseconds on as time goes on?
If not, wouldn't it reset to 0 at some point?
_________________
Calehay
Back to top
View user's profile Send private message AIM Address
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Nov 23, 2007 6:05 pm    Post subject: Reply with quote

I hope you're not looking at the plotscript dictionary on the wiki. That one hasn't been reuploaded in months.

milliseconds reports milliseconds since the computer turned on. It loops over to -2147483648 after 2147483647 (provided you are using a nightly. This fix would have appeared in Ubersetzung+, but that was never released. But it only loops over every 45 days, so you should be safe enough) Anyway, it is perfectly safe to use despite rolling over occasionally, as long as you always subtract one milliseconds value from another!

For example, in 32 bit signed arithmetic, -2147483648 -- 2147483647 == 1

Now, if the script is rewritten to

Code:
script, wait milliseconds, ms, begin
  ms += milliseconds
  while (milliseconds << ms) do (wait)
end


Then there is a problem: If when calling the script milliseconds is about to overflow, 2147483640, say, and ms goes over that, 10 say, then

ms := 10
ms += milliseconds # 10 + 2147483640 = -2147483646

Now milliseconds >= ms and it doesn't wait at all.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group