Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Willdon on Wed 21/04/2010 21:00:43

Title: SetTimer Func not working (SOLVED!!)
Post by: Willdon on Wed 21/04/2010 21:00:43
ok, So I am trying to make an FMV game, and this is the very beginnings of my script.

I have a SetTimer function, but it is not changing rooms after the timer is over. any suggestions? Thanks!

// room script file
Theora* video;
float rot = 0.0;

function repeatedly_execute_always() {
   if(video) {
     video.DrawEx(DsBackground, 160.0, 120.0, 2.0, 1.0, 4.0, RtScreen);
     if(System.HardwareAcceleration) video.DrawEx(DsScene, 260.0, 120.0, 0.25, 0.25, rot, RtScreen);
     video.NextFrame();
     rot += 0.2;
   }
}

function room_Load() {
 Display("Welcome to Joshua's Interactive movie test!");

}
function TVstand_AnyClick()
{
 
 SetTimer(1, 160);
 video = Theora.Open("josh.theora.ogg");
 video.loop = false;  
 SetGameSpeed(24); // you don't need to use the same fps as the video like this, but it's easiest this wa
 cjosh.Walk(213, 160, eBlock, eWalkableAreas);
 bool loop;        // enable/disable automatic looping
 

}


function room_AfterFadeIn()
{
 {
 PlaySound(1);
 PlayMusic(1);
 {
 if (IsTimerExpired(1)) {
 cjosh.ChangeRoom(2);}
 }
}
Title: Re: SetTimer Func not working
Post by: GarageGothic on Wed 21/04/2010 21:15:12
The IsTimerExpired check should be in repeatedly_execute_always, not room_AfterFadeIn.
Title: Re: SetTimer Func not working
Post by: Calin Leafshade on Wed 21/04/2010 21:15:39
also, display is a blocking function and shouldnt be done in room_load.
Title: Re: SetTimer Func not working
Post by: Willdon on Wed 21/04/2010 21:23:45
Ah! I see...When I put it under Repeatedly_execute_always, it gives me an engine error which states:

"This command cannot be used within non-blocking events such as repeatedly_execute_always.

After the movie is  up, I want AGS to shift rooms so I can have another interactive screen.

Here is the effect I am trying to acheive:

http://www.youtube.com/watch?v=T3gPKvO6kwI&feature=related
Title: Re: SetTimer Func not working
Post by: GarageGothic on Wed 21/04/2010 21:30:17
Ah yes, please try repeatedly_execute() instead of repeatedly_execute_always()
Title: Re: SetTimer Func not working
Post by: Willdon on Wed 21/04/2010 21:36:50
Thanks to the both of you, HOWEVER, an issue remains.

It stays on Room 1. Does not make the switch @ all.
Title: Re: SetTimer Func not working
Post by: Khris on Wed 21/04/2010 21:48:44
To check whether a certain piece of code is called at all, put a Display command in there.

Is cjosh the player character?
Try player.ChangeRoom(2); instead.
Title: Re: SetTimer Func not working
Post by: Willdon on Wed 21/04/2010 21:59:09
DUH! sorry I just did a brain dump.

*FACEPALM*


And I tried Player.ChangeRoop(2); yet, to no avail.

I tried putting a display command in, and it turns out the code isnt being read? What now?
Title: Re: SetTimer Func not working
Post by: GarageGothic on Wed 21/04/2010 22:53:08
You know, I wonder if you even need a timer. I'm not at all familiar with the theora module, but looking at the documentation I think you could do something like this, if you want the end of the video to be the event triggering room change:

function repeatedly_execute_always() {
    if(video) {
      if (video.ended) player.ChangeRoom(2); // <---- Added this line
      video.DrawEx(DsBackground, 160.0, 120.0, 2.0, 1.0, 4.0, RtScreen);
      if(System.HardwareAcceleration) video.DrawEx(DsScene, 260.0, 120.0, 0.25, 0.25, rot, RtScreen);
      video.NextFrame();
      rot += 0.2;
    }
}
Title: Re: SetTimer Func not working
Post by: Willdon on Wed 21/04/2010 23:23:09
Wow!  :)

I appreciate your input. :)

I do have a question though, should I rename (VIDEO.ended) to my file name?
Title: Re: SetTimer Func not working
Post by: GarageGothic on Wed 21/04/2010 23:31:37
No, you've declared "video" as a pointer to a member of the Theora class, and already defined it as pointing to your ogg file in the line "video = Theora.Open("josh.theora.ogg");", so you shouldn't rename it, most likely you would just get an error message.

I'm not very good at explaining technical stuff - try looking up "Pointers in AGS" and "Pointers for programming newbies" (no really, that's the title of the section, not an insult :)) in the manual for a more thorough overview.
Title: Re: SetTimer Func not working
Post by: Willdon on Wed 21/04/2010 23:35:56
 ;D

No insult taken bud. lol

I understand that concept now, however, I am STILL unable to change rooms!! lol

This is gonna bug me. :P

If you want to take a look, here is my ORIGINAL script before your revisions.

// room script file
Theora* video;
float rot = 0.0;

function repeatedly_execute_always() {
    if(video) {
      video.DrawEx(DsBackground, 160.0, 120.0, 2.0, 1.0, 4.0, RtScreen);
      if(System.HardwareAcceleration) video.DrawEx(DsScene, 260.0, 120.0, 0.25, 0.25, rot, RtScreen);
      video.NextFrame();
      rot += 0.2;
    }
}

function room_Load() {
  Display("Welcome to Joshua's Interactive movie test!");
}
function TVstand_AnyClick()
{
  TVstand.Enabled = false;
  video = Theora.Open("josh.theora.ogg");
  video.loop = false; 
  SetGameSpeed(24); // you don't need to use the same fps as the video like this, but it's easiest this wa
  cjosh.Walk(213, 160, eBlock, eWalkableAreas);
  bool loop;        // enable/disable automatic looping
  SetTimer(1, 160);

}


function room_AfterFadeIn()
{
  {
  PlaySound(1);
  PlayMusic(1);
 
  }
}
function repeatedly_execute()
{
  if (IsTimerExpired(1)){
  TVstand.Enabled = true;}
  player.ChangeRoom(2);
}
Title: Re: SetTimer Func not working
Post by: GarageGothic on Wed 21/04/2010 23:49:36
What is strange is that you say the player doesn't change rooms, because as its currently written, this piece of code should send him to room 2 every game loop.

function repeatedly_execute()
{
 if (IsTimerExpired(1)){
 TVstand.Enabled = true;}
 player.ChangeRoom(2);
}



If I don't misunderstand the intention, I think it should have been

function repeatedly_execute()
{
 if (IsTimerExpired(1)){
   TVstand.Enabled = true;
   player.ChangeRoom(2);
   }
}


So, what I'm wondering is whether your rep_exec script is running at all. I seem to remember something about repeatedly_execute() not working if simply added to the script. Try adding a room event (yellow lightening bolt icon) in the room editor and choose Repeatedly Execute, then place your code in the auto-generated function and see if it works now.
Title: Re: SetTimer Func not working
Post by: Khris on Wed 21/04/2010 23:51:06
I was just about to post this, GG is correct.

Adding repeatedly_execute() will only work for global scripts, not room scripts.
Title: Re: SetTimer Func not working
Post by: Willdon on Thu 22/04/2010 00:12:38
YES!!!!

Thank you! But as I'm guessing will be VERY common in game design, I have a NEW problem.  :P

EDIT: BUT I think I may be able to address the issue with a pointer. :)