Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jeopardy on Fri 16/05/2008 04:33:41

Title: Scripting for objects in seperate rooms
Post by: Jeopardy on Fri 16/05/2008 04:33:41
I have checked the BFAQ, checked the built in help menu, done a search in both the knowledge base and the forums, and I have not found the answer.

Here's my Problem: I have an event in the global script, a dialog, and when this event is finished, I want to make an object visible in another room, how do I do this? I also need to know how to do it on a room to room basis, as aposed to Global script.

Thank you for your help
Title: Re: Scripting for objects in seperate rooms
Post by: Khris on Fri 16/05/2008 06:53:20
Other room thread count is now: 346'741
Just kidding.

-Somewhere inside the dialog script, put: "run-script 1"

-Then add this to the global script:
bool obj_is_visible;
export obj_is_visible;

function dialog_request(int p) {
  if (p==1) obj_is_visible = true;
}


-Add this to the global header: "import bool obj_is_visible;"

-In the room's before fadein event, put: "if (obj_is_visible) oObjectname.Visible = true;"


obj_is_visible is now a global boolean variable, initially false.
Running the dialog will call run-script 1 -> dialog_request(1), thus turning the variable to true.
When the room is loaded, the global variable is checked for being true and the object is turned visible if it is.
Title: Re: Scripting for objects in seperate rooms
Post by: Jeopardy on Fri 16/05/2008 15:36:11
I can't get this to work at all, I just keep get errors, I'm using v3.0.1 does that make any difference? Also I'm not trying to script directly into the dialog but the scripting that triggers it, I'm not sure if that was obvious I tried it both ways though
Title: Re: Scripting for objects in seperate rooms
Post by: Khris on Fri 16/05/2008 16:06:32
a) If the player doesn't need to select a specific option, you don't need the dialog-request stuff, correct.

b) You expect us to help you, so why don't you tell us exactly what errors you're getting and show us the lines that caused them and the surrounding code...? I don't get it that this has to be mentioned explicitly time and again.
The code should work for any recent version, btw.
Title: Re: Scripting for objects in seperate rooms
Post by: monkey0506 on Fri 16/05/2008 16:25:23
Based on the original post I get the feeling he may want to do this for more than one object, in more than one room. In which case the simplest solution may in fact be to use the OtherRoom module.

However, even in that case he would still have to have a basic grasp on scripting. Presumably he knows at least enough to be able to plug the code in somewhere so as to yield errors. But it would seem he's putting it in the wrong places. Knowing where precisely he put what would help.

The way I understand it, he wants the object to become visible (in the other room) after the dialog is finished. IIRC there's no sort of on-dialog-end function, but putting the run-script in at the end of the dialog script should be sufficient.

At least he did his research before posting... ;D

Like Khris said, we'll need to know what code you've put where, and what error messages you're getting (exact messages; use Ctrl+C to copy the message).
Title: Re: Scripting for objects in seperate rooms
Post by: Jeopardy on Fri 16/05/2008 20:05:56
I tried again and had a bit more of a grasp of what I was doing. here's the error I'm getting now

GlobalScript.asc(408): Error (line 408): Undefined token 'run'

this is coming from the "run-script 1 line"

I tried that module, but I couldn't seem to get it to do what I wanted it to do, I'm only beginning so my scripting is fairly basic.

Here the block of code that that is contained in

function cTlgrphr_UseInv()
{
dTele.Start();
run-script 1
Display ("To: Messrs. Acherman");
Display ("I am more than happy to accept your task, I shall disembark immediately.");
Display ("Signed: Simon Wethers");
}
Title: Re: Scripting for objects in seperate rooms
Post by: monkey0506 on Fri 16/05/2008 21:36:45
You're mixing up dialog scripts with regular scripts. Your "regular" scripts are the ones that accept normal script commands like you're using. "run-script" is a dialog script command. The dialog system has its own specialized scripting, designed to make it easier, and structured more like the script for a play. You can't use regular script commands in a dialog script, and you can't use dialog script commands in a regular script, so you'll need to understand the differences.

First we need to open our global script (Scripts->GlobalScript.asc) and put the following lines:

bool obj_is_visible;
export obj_is_visible;


In GlobalScript.ash (the global script header) we need to put this line:

import bool obj_is_visible;

Next you need to open your dialog (under Dialogs in the right-hand pane), and then on the right-hand side you will have the area where you can type your dialog script. An example from the manual:

@1
ego: "Hello. How are you?"
narrator: The man looks you in the eye.
otherman: ...
otherman: "I'm fine."


If you only had one option then your final line would be the command stop. Since you want to call run-script 1 before you end your dialog, it would look like this:

@1
ego: "Hello. How are you?"
narrator: The man looks you in the eye.
otherman: ...
otherman: "I'm fine."
run-script 1
stop


Then, back in your global script (Scripts->GlobalScript.asc), you should put the dialog_request function like this:

function dialog_request(int script) {
  if (script == 1) {
    Display ("To: Messrs. Acherman");
    Display ("I am more than happy to accept your task, I shall disembark immediately.");
    Display ("Signed: Simon Wethers");
    obj_is_visible = true;
  }
}


The reason you need to put the Display statements here is because Dialog.Start is a delayed command. That is, it won't be called until the end of the script function, so all the Display commands would be run prior to the dialog unless you do it this way. This is the reason why we set our object flag here as well.

Next  we need to open our room that we want to turn the object on in. In the Events pane for this room (the lightning bolt icon) we need to create the "Enters room (before fadein)" event. Click on the "..." button at the right-hand side. Then in the room script we'll now have a function room_Load. Inside that function put this line:

if (obj_is_visible) oObjectname.Visible = true;

You'll need to replace "oObjectname" with the script o-name of your object, or "object[ X ]" where X is the object's ID number.
Title: Re: Scripting for objects in seperate rooms
Post by: Jeopardy on Sat 17/05/2008 07:03:42
It works now, now if I want to do this to more than one object at a time, how do I do that?

also, if I'm going to make another script on this time connected to an actual event rather than a dialog, how about that, I guessing it's probably only a couple lines of code.
Title: Re: Scripting for objects in seperate rooms
Post by: Khris on Sat 17/05/2008 12:47:47
Did you understand the provided solution?
Because that's the point of this forum.
I don't mean to be rude, but it looks like you're simply waiting for someone else to do your work.
Title: Re: Scripting for objects in seperate rooms
Post by: Jeopardy on Sat 17/05/2008 18:51:14
Not so much a tutorial, I'm more looking for clarification. I don't understand what makes it recognize that as "script 1". I'm sorry I don't grasp this but I've gone 21 years without learning how to code anything AT ALL, but using common knowledge, if I know how the script recognizes that as "script 1" I should be able to figure out for myself how to create "script 2".

Also, you're not being rude, I realise I may sound a little demanding, but I'm just confused, I understand the implementation, but not the code it's self.
Title: Re: Scripting for objects in seperate rooms
Post by: Khris on Sun 18/05/2008 01:48:38
Ok, I'll try to explain:
The run-script X command is for running regular script commands from within a dialog script. Since there'll usually be more than one occasion, X is used to tell AGS which code to run.
If AGS encounters the run-script command, it will call dialog_request(X);
X is the single parameter of the function call, an integer variable holding a whole number.
run-script 2 will call dialog_request(2); so all you have to do is to check the value of the parameter, then run the accordant code:
function dialog_request(int param) {
  if (param == 1) {
    // this will be run on run-script 1
    ...
  }
  if (param == 2) {
    // this will be run on run-script 2
    ...
  }
  if (param == 3) {
    // this will be run on run-script 3
    ...
  }
  ...
}
Title: Re: Scripting for objects in seperate rooms
Post by: Jeopardy on Sun 18/05/2008 02:13:42
Thanks alot everybody, I think that's everything I need to know.

EDIT: I thought I had it figured out, but now when it runs script 2 which actually in terms of gameplay comes first, then it make both obejects visible.

function dialog_request(int script) {
  if (script == 1) {
    Display ("To: Messrs. Acherman");
    Display ("I am more than happy to accept your task, I shall disembark immediately.");
    Display ("Signed: Simon Wethers");
    obj_is_visible = true;
    }
  if (script == 2)
  {
    obj_is_visible = true;
  }
  }


function room_Load()
{
if (obj_is_visible) oHarborbutton.Visible = true;
if (obj_is_visible) oTelebutton.Visible = true;
}


// Dialog script file
@S  // Dialog startup entry point
cSmn: This sounds intriguing.
cSmn: I'll go to the Telegrapher and respond right away.
run-script 2
stop


both objects are in the same room.

I know I got the code right, because the game runs and the function works, it just doesn't work the way I want it to, how do I make it so it doesn't activate both objects, and just one at a time? It doesn't look like there's any command to tell it which is which.
Title: Re: Scripting for objects in seperate rooms
Post by: Khris on Tue 20/05/2008 02:39:53
You're going to need two different variables; with your code, if obj_is_visible equals true, both objects get turned visible.
I'd use e.g. harbor_is_vis and tele_is_vis.
Title: Re: Scripting for objects in seperate rooms
Post by: Jeopardy on Tue 20/05/2008 03:51:51
Quote from: KhrisMUC on Tue 20/05/2008 02:39:53
You're going to need two different variables; with your code, if obj_is_visible equals true, both objects get turned visible.
I'd use e.g. harbor_is_vis and tele_is_vis.

Thanks I didn't know I could change the wording. This is it then, all I need to know, Hopefully.