change room immediately?

Started by spook1, Fri 17/03/2006 19:24:44

Previous topic - Next topic

spook1

I feel rather silly, asking another easy question. But I cannot find the answer anywhere.

It has something to do with code running in the background??

I have a set of cEgo.Say("   "); commands.
(I must work this way, rather than use the dialog because I use %d variables in my speech)

At a certain point a function is called, and under conditions a transition must be made to another room.
The change is not made though, but the cEgo.Say("   "); speech commands continue to go on.

The funtion is something like :
Code: ags

function CheckSettings(int StartHB, int fluctuatie, int alarmgewenst){ 	
if ((StartHB + fluctuatie > GetTopLimit(StartHB))  || (StartHB + fluctuatie < GetBottomLimit(StartHB))  ){  
                Display("Alert");
	PlayAmbientSound(1, 1, 255,0,0);
	
	Display("Operatie mislukt, contract overleden...");
	StopAmbientSound(1);				cEgo.ChangeRoom(7); 
}

The change is never made though in the script below. Worse: the final changeroom generates an error: "already changeroom due"

here is the complete  script
Code: ags

if (GetGlobalInt(1)==1){
  cNurse.Say("Nou is het afwachten .... of ie het doet!");
  cNurse.Say("Onze kwaliteitsnorm eist 3 correcte alrams op rij.");
  cNurse.Say("Als u dat haalt blijven wij uw klant");
  cNurse.Say("Blijft u maar even rustig afwachten. u hoeft niets te doen");
  CheckSettings(80, 22, 1);   
			
  CheckSettings(70, -12, 0);  
  cNurse.Say("Laat eens even checken wat de waarden nu zijn meneer");
      
  CheckSettings(110, 12, 1);   
  cNurse.Say("En dat was drie. Ik ga naar bed en u kunt naar huis.");
  cNurse.Say("Onze dank is groot!!");
  cEgo.ChangeRoom(7);
	 }  


any suggestions would be very welcome      }

Khris

ChangeRoom commands won't be executed until the current script has finished. They are queued while the script is running, but two or more ChangeRooms in the queue will generate the error you get.

The workaround is to use several RunScript interactions, each with the ChangeRoom command (or the function calling it) at the very end.

spook1

Thanbks for helping out. There is one thing I do not understand yet though.

I thought that i did have different runscript interactions by calling cEgo.Say("..."); each time again. In btween two of these commands the function could make the room change, couldn't it?
Well, obviously not, but I fail to get the logic I'm afraid.

Thanks for thinking along with me,

martijn

Khris

You're talking of script commands.
An interaction is one of the commands from the dropdown menu where one usually selects "RunScript".

You'll have to add four RunScript interactions and split your code.
Like this:

Talk to character
L__RunScript
L__RunScript
L__RunScript
L__RunScript

First RunScript interaction:
Code: ags
if (GetGlobalInt(1)==1) {
Ã,  cNurse.Say("Nou is het afwachten .... of ie het doet!");
Ã,  cNurse.Say("Onze kwaliteitsnorm eist 3 correcte alrams op rij.");
Ã,  cNurse.Say("Als you dat haalt blijven wij uw klant");
Ã,  cNurse.Say("Blijft you maar even rustig afwachten. you hoeft niets te doen");
Ã,  CheckSettings(80, 22, 1);
}


Second one:
Code: ags
if (GetGlobalInt(1)==1) {
Ã,  CheckSettings(70, -12, 0);
}


Third:
Code: ags
if (GetGlobalInt(1)==1) {
Ã,  cNurse.Say("Laat eens even checken wat de waarden nu zijn meneer");
Ã,  CheckSettings(110, 12, 1);
}


Fourth:
Code: ags
if (GetGlobalInt(1)==1) {
Ã,  cNurse.Say("En dat was drie. Ik ga naar bed en you kunt naar huis.");
Ã,  cNurse.Say("Onze dank is groot!!");
Ã,  cEgo.ChangeRoom(7);
}


That way, the room change will happen immediately.

spook1

Ok, I almost get it. Thanks for your ongoing interest in my little troubles ;-)

What i do not get yet: are the  runscripts not connected to "once in a room" events like: first time enter room, enter room before fade in, enter room after fade in, leave room, repeatedly execute etc.

Can I make a special Runscript that occurs more than one time?

My events should happen after I talked to a character (so they are based on a poll of a Global Integer (see my other question today :-))
How can I split that up in four different events??

regards Martijn

Khris

Almost everything in AGS has their own interactions, objects, inv items, hotspots, you name it. Most of them are triggered by clicking on them.
You are listing only the room interactions.

What AGS does is basically the following: it waits for the user to click somewhere, then calls the on_mouse_click() in the global script.
By default, this leads to ProcessClick(mouse.x, mouse.y, mouse.Mode) being called.
In your case, if you clicked on the nurse with the talk cursor, AGS checks if there's any actions added to the nurse's Talk to character interaction. Usually (if the developer uses scripting rather than the limited interaction editor commands) it'll find a RunScript interaction which is associated to a function in the global script. This function is generated and added as soon as one adds the RunScript interaction.

Those functions are added to the room script for objects, hotspots, regions and so on, since they belong to a certain room. Room independant things like characters or inventory items have their code added to the global script.

A "special Runscript that occurs more than one time" would be the repeatedly execute function in the global script. It is run 40 times a second. Every room has its own repeatedly execute interaction, if any Actions are added there, they are run 40 times a second, too.

If you want the events to happen after you talked to a character, select the char in the Editor, click on the "Interactions..." button, double click on "Talk to character" and select "RunScript". A new function called characterX_a() is added to the end of the global script. You can edit it by clicking on the "Edit Script" button, or directly by accessing the global script. To find the right one, there's a comment which in your case would be "// script for Character X (NURSE): Talk to character"

To split the code, in the interaction editor for the nurse, right click on the existing "Run Script" interaction and choose "Add action after this...". Then select "RunScript" again.

Btw, finally adressing your original problem, it occured to me that you don't need to split the code at all.
Make the Check_Settings function return zero if the room change shall happen, one otherwise:
Code: ags
function CheckSettings(int StartHB, int fluctuatie, int alarmgewenst) { 
Ã,  if ((StartHB + fluctuatie > GetTopLimit(StartHB))Ã,  || (StartHB + fluctuatie < GetBottomLimit(StartHB)) ) {
Ã,  Ã,  Display("Alert");
Ã,  Ã,  PlayAmbientSound(1, 1, 255,0,0);
Ã,  Ã,  Display("Operatie mislukt, contract overleden...");
Ã,  Ã,  StopAmbientSound(1);
Ã,  Ã,  return 0;
Ã,  }
Ã,  else
Ã,  Ã,  return 1;
}


Now, use this as the nurse's talk to RunScript:
Code: ags
if (GetGlobalInt(1)==1){
Ã,  cNurse.Say("Nou is het afwachten .... of ie het doet!");
Ã,  cNurse.Say("Onze kwaliteitsnorm eist 3 correcte alrams op rij.");
Ã,  cNurse.Say("Als you dat haalt blijven wij uw klant");
Ã,  cNurse.Say("Blijft you maar even rustig afwachten. you hoeft niets te doen");
Ã,  if (CheckSettings(80, 22, 1)) {
Ã,  Ã,  if (CheckSettings(70, -12, 0)) {
Ã,  Ã,  Ã,  cNurse.Say("Laat eens even checken wat de waarden nu zijn meneer");
Ã,  Ã,  Ã,  if (CheckSettings(110, 12, 1)) {
Ã,  Ã,  Ã,  Ã, cNurse.Say("En dat was drie. Ik ga naar bed en you kunt naar huis.");
Ã,  Ã,  Ã,  Ã, cNurse.Say("Onze dank is groot!!");
Ã,  Ã,  Ã,  }
Ã,  Ã,  }
Ã,  }
Ã,  cEgo.ChangeRoom(7);
}

SMF spam blocked by CleanTalk