Make an object appear only after a dialoge option has been chosen

Started by Minitay, Sat 09/01/2016 08:57:16

Previous topic - Next topic

Minitay

i want to make an object appear only after the player has chosen a specific dialoge option.
i've been thinking to use something like this...

Code: ags

function PC_Talk()
{
  dDialog1.Start ();
  if (dDialog1.HasOptionBeenChosen(5))
  //continue script here
  
}


but i really dont know what to do since the object's name (H74) isnt identified in the global script itself...

Slasher

Quotebut i really dont know what to do since the object's name (H74) isnt identified in the global script itself...
Objects in the Global (and dDialogs) use the objects ID and not the name:

Code: ags

//Example
object[3].Visible=true;

Minitay

Quote from: slasher on Sat 09/01/2016 10:21:31
Quotebut i really dont know what to do since the object's name (H74) isnt identified in the global script itself...
Objects in the Global (and dDialogs) use the objects ID and not the name:

Code: ags

//Example
object[3].Visible=true;


Code: ags

function PC_Talk()
{
  dDialog1.Start ();
  if (dDialog1.HasOptionBeenChosen(5)) 
  object[0].Visible=true;
   
}

i did it, but when i enter the game, the object is still visible before the option has been chosen

also, in the object's property grid, if i turn the visibility to false the object does not appear after the option has been chosen

(on top of that, the dialog closes after option 5, even though option 6 is the closing option, so i would expect it would act as needed if it decides to close the dialoge...)

Minitay

oh, i identified the problem more throughouly:

the thing is that the object DOES appear, but only if you pressed the option... and chose to dialogue again.
as in, it doesnt appear immediately after the option has been chosen, but after the option has been chosen AND the dialogue started again.

ill try to be more understandable...

>object not visible

  >dialoge start

   >option 5 chosen

  >dialoge end

>dialoge start

>object visible


how do i fix this.

Grok

You could check if the dialog option has been chosen in the room script.

In function room_RepExec() you could put in

Code: ags

if (dDialog1.HasOptionBeenChosen(5)) 
  H74.Visible=true; 


If the object is not visible, this will turn the object visible, after the dialog has stopped.

Minitay

Quote from: Grok on Sat 09/01/2016 12:11:02
You could check if the dialog option has been chosen in the room script.

In function room_RepExec() you could put in

Code: ags

if (dDialog1.HasOptionBeenChosen(5)) 
  H74.Visible=true; 


If the object is not visible, this will turn the object visible, after the dialog has stopped.

i did that, but nothing happens... as in, the object doesn't appear at all..

cat

The problem is, that dDialog1.Start() is not blocking AFAIK. So you start the dialog and immediately after that, check for option chosen (which at that point in time, was not yet chosen).

There is a much better solution to this: Just make the object visible from WITHIN the dialog script. In the dialog script itself, where you handle the desired option (5 in this case), indent the line and write the AGS code. Take a look at the manual in the section "Dialogs" and "Using scripting commands in dialogs".

Grok

Quote from: Minitay on Sat 09/01/2016 17:23:31


i did that, but nothing happens... as in, the object doesn't appear at all..


That's strange. This might not necessarily be the best way of doing it, but it should have worked.

Is the name of the object correct?
Is there something in the code that turns the object's visibility to false, that could counteract the command?


You could put in the follow function in your room script just for testing
Code: ags

function on_key_press(eKeyCode keycode) 
{
  if (keycode == eKeyA) 
     if(H74.Visible==true)
        H74.Visible=false;
     else
        H74.Visible=true;
}



Pushing the "A" key repeatedly should now turn on and off the visibility of H74. If this doesn't work then you have a problem somewhere that you need to find.


Minitay

Quote from: cat on Sat 09/01/2016 19:10:28
The problem is, that dDialog1.Start() is not blocking AFAIK. So you start the dialog and immediately after that, check for option chosen (which at that point in time, was not yet chosen).

There is a much better solution to this: Just make the object visible from WITHIN the dialog script. In the dialog script itself, where you handle the desired option (5 in this case), indent the line and write the AGS code. Take a look at the manual in the section "Dialogs" and "Using scripting commands in dialogs".

i did it!!! you were right!! thanks!!!!111 :DD
and thank you Slasher for trying to help too!!

Khris

As is stated in the manual, while Dialog.Start() is in fact blocking (at least by default), it is also one of multiple commands that is queued and only run after the current function finishes. That is why the object only appeared when (and before) you talked to the character a second time, because when you talk to them the first time, HasOptionBeenChosen(5) is tested before the dialog starts. The next time around of course, if you chose option 5 in the first conversation, the object is turned on, then the dialog starts for the second time.

Many beginner problems arise from not understanding how the engine works internally; it can be very helpful to read the respective manual parts.

Given that it has been possible to use regular script commands inside dialog scripts for years now, that's the proper solution to the problem, as cat described.

SMF spam blocked by CleanTalk