Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kinoko on Mon 13/02/2006 11:54:13

Title: Rep_exe_always problem, perhaps.
Post by: Kinoko on Mon 13/02/2006 11:54:13
I have a room that I want to scroll upwards, while also running a TypeLine function. Both work perfectly independantly but they don't seem to like each other.

I start them at roughly the same time, and they run fine, but I can't start a new TypeLineInvis until the scrolling stops. It will just wait until the scrolling is done and then run the next line of text.

Is this something to do with them both being in repeatedly_execute_always?

This is in the room script:

function repeatedly_execute_always() {
vpx=GetViewportX();  // Get current viewport coordinates
vpy=GetViewportY();

oPurplestars.SetPosition(0, oy1-((vpy*5)/15)); //furthest parallax object
oWhitestars.SetPosition(0, oy2-((vpy*5)/10));//closest parallax object moves
 
}

#sectionstart room_c  // DO NOT EDIT OR REMOVE THIS LINE
function room_c() {
  // script for Room: Player enters room (after fadein)
if (GetGlobalInt(28)==1) {
  TypeLineInvis("Line One,", 5, 200, 20, 160, 275, 11);
  yposit=GetViewportY();
  xposit=0;
  while (yposit > 0) {
SetViewport(xposit, yposit);
Wait(2);
yposit--;
}
}


and this is in the grobal script:

function TypeLineInvis (const string say, int delay, int wait, int xpos, int vpos, int width, int queue) {
if (IsGamePaused()==0) {
StopMoving(EGO);
SetTextWindowGUI(31);
StrCopy(displayedline,"");
StrCopy (line, say);
typecount=0;
textid = CreateTextOverlay(xpos, 100, 400, 1, 1, displayedline);
length=StrLen(line);
SetTimer(6, delay);
delaya=delay;
vposa=vpos;
xposa=xpos;
waita=wait;
widtha=width;
cue=queue;
}
}


In repeatedly_execute_always:

if (IsTimerExpired(6)) {
  if (typecount<length) {
    StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,typecount));
    SetTextOverlay(textid,xposa,vposa,widtha,1,1,displayedline);
     if (StrGetCharAt(line,typecount)!=' ') PlaySound(1);
     typecount++;
     if (typecount==length) {
       if (waita>0) SetTimer(7, waita);
       else RemoveOverlay(textid);
       }
             else {
       SetTimer(6, delaya);
       }
  }
}



if (cuetli==1) {
  else if (cue==11) TypeLineInvis("Line Two", 5, 200, 20, 160, 275, 12);
  else if (cue==12) TypeLineInvis("Line Three,", 5, 200, 20, 160, 275, 13);
//// ... etc
  cuetli--;
}


AND this is in repeatedly_execute:

if (IsTimerExpired(5)) {
  if (cue==11) cuetli=1;
}


It's a bit all over the place, but it needs to be for the function to work with all the lines I use with it. Trust me.

Basically, the final number of TypeLineInvis is the number that determines what the next line to run after it has been removed will be.
Title: Re: Rep_exe_always problem, perhaps.
Post by: SSH on Mon 13/02/2006 12:10:30
Do timers run when the game is blocked? I don't think so...

You could make a timer from a variable and decrementing it in rep_ex_always() instead...
Title: Re: Rep_exe_always problem, perhaps.
Post by: Kinoko on Mon 13/02/2006 12:19:29
They don't?? God damn, I didn't realise >_< Gimme a sec to see if this works.. Thanks!

EDIT: That doesn't appear to work, at least not the way I did it.


function TypeLineInvis (const string say, int delay, int wait, int xpos, int vpos, int width, int queue) {
if (IsGamePaused()==0) {
StopMoving(EGO);
SetTextWindowGUI(31);
StrCopy(displayedline,"");
StrCopy (line, say);
typecount=0;
textid = CreateTextOverlay(xpos, 100, 400, 1, 1, displayedline);
length=StrLen(line);
                invisdelay=delay;
                invistimer++;
delaya=delay;
vposa=vpos;
xposa=xpos;
waita=wait;
widtha=width;
cue=queue;
}
}
}



if (invistimer>0) {
invistimer++;
if (invistimer==invisdelay) {
invistimer=0;
if (typecount<length) {
StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,typecount));
SetTextOverlay(textid,xposa,vposa,widtha,1,1,displayedline);
if (StrGetCharAt(line,typecount)!=' ') PlaySound(1);
typecount++;
if (typecount==length) {
if (waita>0) invistimera++;
else RemoveOverlay(textid);
}
else invistimer++;
}
}
}
if (invistimera>0) {
  invistimera++;
if (invistimera==waita) {
  invistimera=0;
RemoveOverlay(textid);
timerfive++;
}
}


if (timerfive>0) {
  timerfive++;
  if (timerfive==40) {
    timerfive=0;
    if (cue==11) TypeLineInvis("Line One", 5, 200, 20, 160, 275, 2);
    //etc
Title: Re: Rep_exe_always problem, perhaps.
Post by: SSH on Mon 13/02/2006 13:57:09
I recommend have a text label ina  gui somehwere that you update every game cycle with your timer values, to make sure they are counting as you expect.
Title: Re: Rep_exe_always problem, perhaps.
Post by: Gilbert on Tue 14/02/2006 01:29:33
Haven't read the long content of this thread yet, but timers should still be running when the game's blocked. However in my opinion decrementing a user defined variable gives you more control, so that's preferred too.
Title: Re: Rep_exe_always problem, perhaps.
Post by: Kinoko on Tue 14/02/2006 02:23:57
Well, maybe so but I've changed it back now because I'd rather just have it working as it was. If that wasn't my initial problem, I'll leave it be. I'd still like to know what the clash is :/ I've tried looking at the code during debugging but nothing seems to explain why.

I'm considering whether the problem is having things running in both the room rep_exe_always and the global rep_exe_always scripts, but I think that may be a long shot, I can't see the sense behind it, and I can't try it til I get home tonight.
Title: Re: Rep_exe_always problem, perhaps.
Post by: Gilbert on Tue 14/02/2006 02:35:19
Actually I have a question, regarding your original codes using timers, was it just because you didn't post all the revalent codes, that I don't see where Timer 5 was set (but it's checked if it expired), and what is the use of Timer 7 (I know, to pause a bit after a line right?) if you didn't check if it expired? Or, was it just a typo, that Timer 5 and Timer 7 meant the same thing?

--EDIT--
Also, was the scrolling code blocking? The "if Timer 5 expired" line was in rep_exe(), if it's used to signal the next line to be displayed, since rep_exe() won't run while the game's blocked so the next line would not be displayed until the scrolling ends. Timer WILL run while blocking, just that the line to check if it expires was in rep_exe, so the check will be done after the scrolling, I think putting that into rep_exe_always should do the trick.
Title: Re: Rep_exe_always problem, perhaps.
Post by: Kinoko on Tue 14/02/2006 02:57:25
Ah, sorry sorry, I did indeed forget to post that part of the code. The timer7 code goes just below the rest, so it looks like:


if (IsTimerExpired(6)) {
Ã,  if (typecount<length) {
Ã,  Ã,  StrFormat(displayedline, "%s%c", displayedline, StrGetCharAt(line,typecount));
Ã,  Ã,  SetTextOverlay(textid,xposa,vposa,widtha,1,1,displayedline);
Ã,  Ã,  Ã, if (StrGetCharAt(line,typecount)!=' ') PlaySound(1);
Ã,  Ã,  Ã, typecount++;
Ã,  Ã,  Ã, if (typecount==length) {
Ã,  Ã,  Ã,  Ã, if (waita>0) SetTimer(7, waita);
Ã,  Ã,  Ã,  Ã, else RemoveOverlay(textid);
Ã,  Ã,  Ã,  Ã, }
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, else {
Ã,  Ã,  Ã,  Ã, SetTimer(6, delaya);
Ã,  Ã,  Ã,  Ã, }
Ã,  }
}

if (IsTimerExpired(7)) {
Ã,  RemoveOverlay(textid);
}


(roughly, did that from memory). That's all in rep_always but the Timer 5 code is in rep_execute.

Reading your edit though, that sounds very much like that may be the problem, and I don't know WHY that never occured to me! >_< I'm half tempted to fly home during my lunch break to try it out...


EDIT: ... and tempted I was! So much so I DID go home for my lunch break. It was just a matter of switching a couple of lines of code and voila! Works perfectly now! ^_^ Thanks so much!! (I may make Release Something yet!)
Title: Re: Rep_exe_always problem, perhaps.
Post by: Kweepa on Wed 15/02/2006 02:07:32
I don't have a solution to your problem, but I think you've been in Japan too long.

Quote from: Kinoko on Mon 13/02/2006 11:54:13
grobal script:
Title: Re: Rep_exe_always problem, perhaps.
Post by: Kinoko on Wed 15/02/2006 04:01:57
Dargh! Nooo! o_o
Title: Re: Rep_exe_always problem, perhaps.
Post by: Gilbert on Wed 15/02/2006 04:05:23
What's wrong with the gurobaru script?




Spoiler
Alright, enough fun. :=
[close]