Non-blocking 'Wait' command?

Started by fiaschetta, Sun 30/04/2006 20:06:33

Previous topic - Next topic

fiaschetta

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.

Ashen

Use Timers.

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.
I know what you're thinking ... Don't think that.

fiaschetta

#2
Well, my script is:

Code: ags
ChangeCharacterView (BOS,8);
SetTimer (20,20);
ChangeCharacterView (BOS,4);


but characterView become only 4... why?

EDIT: No need to quote the whole previous post.

Ashen

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:

Code: ags

if (IsTimerExpired(20)) { //
  cBos.ChangeView(4); // Or ChangeCharacterView (BOS, 4) - but that's obsolete after V2.7
}
I know what you're thinking ... Don't think that.

fiaschetta

#4
Ok,
my script:
Code: ags
SetTimer (1,20);
ChangeCharacterView (BOS,11);
if (IsTimerExpired(1) == 1)Ã,  { //
Ã,  ChangeCharacterView (BOS,8); }


But the charcacter(bos) never changeview( 8 ).. why?

Ashen

#5
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(..).
I know what you're thinking ... Don't think that.

fiaschetta

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...

Ashen

#7
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.;
Code: ags

// 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.");
}
I know what you're thinking ... Don't think that.

fiaschetta

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

Ashen

So taking the object happens when you interact with the same hotspot as changes the view? In that case, you want something like:
Code: ags

//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.
I know what you're thinking ... Don't think that.

fiaschetta

#10
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

SSH

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:

Code: ags

//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");
}


Code: ags

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


Code: ags

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

12

SMF spam blocked by CleanTalk