Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fiaschetta on Sun 30/04/2006 20:06:33

Title: Non-blocking 'Wait' command?
Post by: fiaschetta on Sun 30/04/2006 20:06:33
Well.
If a secondary character is in view 4 then i can do a determined action.. 
However the secondary character must be in view 4 for 50 seconds then he returned in view 3 and i can't do the action... 

My script is:

charcte[re].changeview[4];
Wait 60

but with "wait" i can't move the cursor of mouse for must the action.
Title: Re: Action while...
Post by: Ashen on Sun 30/04/2006 20:29:22
Use Timers (http://www.adventuregamestudio.co.uk/manual/SetTimer.htm).

So, instead of the Wait(60) command you'd use SetTimer(1, 60*GetGameSpeed()). (NOTE: Both the timer command and Wait are measured in game loops not actual seconds. The default speed is about 40 loops per second, so Wait(60) would only pause it for about 1.5 seconds - the *GetGameSpeed()  bit corrects for this.) Then use IsTimerExpired in repeatedly_execute to change the view back after the set time. Do a search for Timers if you need more detail.
Title: Re: Action while...
Post by: fiaschetta on Mon 01/05/2006 03:53:49
Well, my script is:

ChangeCharacterView (BOS,8);
SetTimer (20,20);
ChangeCharacterView (BOS,4);


but characterView become only 4... why?

EDIT: No need to quote the whole previous post.
Title: Re: Action while...
Post by: Ashen on Mon 01/05/2006 11:49:04
Did you read the last bit of my reply? Or search for detail like I suggested?

QuoteThen use IsTimerExpired in repeatedly_execute to change the view back after the set time. Do a search for Timers if you need more detail.

OK, a little vague I'll admit, but I thought the manual entries were clearer. Timers don't work exactly like Wait() commands - since they're non-blocking (unlike Wait(), you can do other things while they're running) the lines after them in script will be run IMMEDIATELY. To have something happen after the timer expires, you need to check the with the IsTimerExpired() command, in the Repeatedly Execute interaction. So, if there isn't one already, add a 'Run Script' to the room's 'Repeatedly execute' Interaction, and set it to this:


if (IsTimerExpired(20)) { //
  cBos.ChangeView(4); // Or ChangeCharacterView (BOS, 4) - but that's obsolete after V2.7
}
Title: Re: Non-blocking 'Wait' command?
Post by: fiaschetta on Mon 01/05/2006 17:42:36
Ok,
my script:
SetTimer (1,20);
ChangeCharacterView (BOS,11);
if (IsTimerExpired(1) == 1)Ã,  { //
Ã,  ChangeCharacterView (BOS,8); }


But the charcacter(bos) never changeview( 8 ).. why?
Title: Re: Non-blocking 'Wait' command?
Post by: Ashen on Mon 01/05/2006 18:00:05
Quote from: Ashen on Sun 30/04/2006 20:29:22
Then use IsTimerExpired in repeatedly_execute to change the view back after the set time.

Quote from: Ashen on Mon 01/05/2006 11:49:04
To have something happen after the timer expires, you need to check the with the IsTimerExpired() command, in the Repeatedly Execute interaction. So, if there isn't one already, add a 'Run Script' to the room's 'Repeatedly execute' Interaction, and set it to this:

As you've got it, it checks if the Timer is expired immediately after you've set it - obviously, it's not going to be, so it doesn't change back. That's why the IsTimerExpired condition has to be in the 'Repeatedly execute' interaction - it'll keep on checking until the Timer does expire.

Again, what version of AGS are you using? If it's later than 2.7, you really should be using Character.ChangeView(..) instead of the obsolete ChangeCharacterView(..).
Title: Re: Non-blocking 'Wait' command?
Post by: fiaschetta on Mon 01/05/2006 18:07:42
my problem is that i need of the timer only use a object...
Pratically, i interact with an hotspost and the charcter(bos) must changeview(4)... while he is in view 4 i can take a object...
Title: Re: Non-blocking 'Wait' command?
Post by: Ashen on Mon 01/05/2006 18:17:07
And? Sorry, I don't see why that's a problem.
The timer code isn't really connected to the Object.
All it should do is change BOS's view back to whatever (you originally had it changing to 8 then back to 4, now it's to 11 and back to 8, but you say you want it in view 4?) after the Timer expires. What you do in that time, and what happens when it expires, doesn't affect the basic procedure.

Note that, as I said in an earlier post, Timers measure in game loops, not seconds - SetTimer(1,20) will probably only give you about half a second to react.

The object bit just needs to check the character's view, e.g.;

// Interact with object
if (cBos.View == 4) {
  // Take Object (turn screen object off, add an inventory item, etc)
}
else {
  Display ("You can't take that now.");
}
Title: Re: Non-blocking 'Wait' command?
Post by: fiaschetta on Mon 01/05/2006 18:39:02
Well 
 
I interact with a hotspot, after the BOS changes View and I can pick up an object. 
 
Then the timer start only after which i interact with hotspot.. 
 
however, now I try as you explain
Title: Re: Non-blocking 'Wait' command?
Post by: Ashen on Mon 01/05/2006 18:53:01
So taking the object happens when you interact with the same hotspot as changes the view? In that case, you want something like:

//Interact with hotspot
if (cBos.View == 4) {
  // Take Object (turn screen object off, add an inventory item, etc)
}
else {
  cBos.ChangeView(4);
  SetTimer(1,20); // or whatever time you actually want.
}


If it's a different hotspot, then the code I gave for Interact with object is still basically right.

Sorry, I'm just having a little trouble understanding exactly what you want to happen, and in what order.
Title: Re: Non-blocking 'Wait' command?
Post by: fiaschetta on Tue 02/05/2006 02:22:38
Well.

I owe taking an object..Ã, 
But if the charcterBOS is not in view 4,Ã,  I can't.Ã, 
However, if i interact with a hotspot, the characterBOS goes in view 4 and I can taking the object.Ã, 
But i can taking the object only in 20seconds because after 20seconds characterBOS returned on his original view (for example 3).

Pratically, I would  that after intercated with hotspot, for 20 second the charcaterbos change view in 4 and after 20second returneds as before
Title: Re: Non-blocking 'Wait' command?
Post by: SSH on Tue 02/05/2006 09:25:08
Let me reiterate to get this clear.

You have 2 hotspots (lets call them A and B)

Interacting with A make you change to view 4 for 20 seconds then com back to previous view

Interacting with B gets you the object if you are using view 4, otherwise you cant get object

NB... what happens when you interact with A with view 4? Does the timer start again?

anyway:


//Interact with B
if (cBos.View == 4) {
  // Take Object (turn screen object off, add an inventory item, etc)
  cBos.AddInventory(iThingy);
} else {
  Display("I can't get it");
}



//Interact with A
cBos.LockView(4);
SetTimer(1, 20*GetGameSpeed()); // 20 seconds



// room's repeatedly_execute
if (IsTimerExpired(1)) {
  cBos.UnlockView();
}