Another Dialoge Question. [SOLVED]

Started by RetroJay, Tue 06/07/2010 02:45:26

Previous topic - Next topic

RetroJay

Hi all good AGS...ers.
I am still using 2.72 (cos I am truly Retro)

Ok. I already know that 'Khris' will have a go at me for this...But here goes.

My problem is.

I have two rooms.
Let's say that Room 1 has an object that is 'NOT' visible and Room 2 has an 'NPC' that the Player can talk to.
I would like to talk to the 'NPC' in Room 2 and on 'option 3' of the dialoge switch the Object 'ON' for Room 1.

Is there a way to do this?

Many thanks.
Jay.

Matti

Easy. You can't directly handle objects from a different room, but you can simply use a variable. Use a bool and change it to true after the player chose option 3 in the dialog (via the dialog request in 2.7 iirc). In room 2, turn the object visible if the bool is true (in the room load). Of course you need a global variable..

RetroJay

Hi Mr. Matti.

Thank you.
I will give that a go and see what happens.
I am fine with Variables.
Not so good with 'Bool's' and 'Global Variables' though :-[

I will experiment and see what happens.

Many thanks
Jay.

Matti

Well, you don't have to use bools. Instead of having a bool set to true or false you can set an int to 1 or 0 or something similar.

You don't have to use global variables neither, but they're more practical since you don't have to import/export them.

Khris

Just to clarify: 2.72 doesn't have a Global Variables pane afaik, so it's export/import alright.

Add this line to the global header:

Code: ags
import bool room1_obj_on;   // make variable global


Add this to the top of the global script:

Code: ags
bool room1_obj_on;   // initial value is false for bools (0 for ints)
export room1_obj_on;   //  export so import can see it


Now we have a global variable called room1_obj_on that can be read and set in any script, global or room.
To change it after the dialog option has been chosen, we need to use dialog_request.
Add this to the global script if the function doesn't exist already:

Code: ags
function dialog_request(int p) {

  // 1: talk to NPC, option 3 -> turn on ... in room 1
  if (p == 1) {
    room1_obj_on = true;   // set global variable
  }
}


This can be called using the dialog command "run-script 1" inside the dialog script of option 3.

The final thing to do is to add this to room 1's load function (enter before fadein event):
Code: ags
  oObject.Visible = room1_obj_on;


*****************************

Actually, you can use one of the dreadful built-in GlobalInts; in this case they are actually convenient because you can set them directly using a dialog command.
Thus you could skip all the export/import/dialog_request business.

On the other hand, the current version of AGS is equally convenient since you create the global variable comfortably using the pane of the same name, on top you can use script commands inside dialog script.
Thus its: 1: create var, 2: add " room1_obj_on = true;" to dialog script, 3: add room_Load line as above

RetroJay

#5
Hi Khris.

Thank you ever so much for your time...again. ;)
All of your instructions are explained so well that I actualy understand what does what and why.

I am unable to try this at the moment as I am away from my 'AGS machine'.
As soon as I do though I will let you know how it went and then hopefuly label this as SOLVED.

Many many thanks.
Jay.

RetroJay

#6
Hi Khris.

Sorry I've been a while in replying. (work sucks)

Thank you very much. That works like a charm.

I do have Two questions though.
If I want to do this again with another NPC and another room.
Do I have to create another 'bool' and use your code over again. Or can I use the 'bool' already created?
 
Also in your script, under 'Dialog_request' what does the 'if (p == 1)' do?
Sorry to ask but I like to understand these things.

Many thanks.
Jay

Khris

The bool is just a way of storing information, in this case what state a piece of your game is in. Whether you're going to need another bool depends on whether the second state is related to the first or not.
(Think of two light switches connected to one lamp vs. two lamps, each with its own switch.)

From your post it sounds like you'd need a second bool.
Thus, in the other NPC's dialog script, put "run-script 2". This command will make ags call "dialog_request(2);", thus the parameter p now has the value of 2.

Consequently, you need to add a few lines to the dialog_request function:

Code: ags
function dialog_request(int p) {

  // 1: talk to NPC, option 3 -> turn on ... in room 1
  if (p == 1) {
    room1_obj_on = true;   // set global variable
  }

  // 2: talk to second NPC
  if (p == 2) {
    // switch second bool
  }
}


There's only one dialog_request function, thus the number after "run-script" determines which block of code is supposed to be executed.
By putting my commands inside an if block that checks the value of p, I can distinguish between the various instances where regular code is to be executed from within a dialog.

RetroJay

#8
Khris.

Aha!
I see it all now...Some of it.

I am truly sorry for asking such, what you may think, are stupid questions.
I just wish to learn. (What does what and why it does it.)

Thank you for all of your help Khris.

Jay signing out. (until next time) ;)

P.s.
If you want to have a look at my new character, and piss poor web page. Then goto www.j-soft.indrek.org ::)


SMF spam blocked by CleanTalk