Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rik_Vargard on Wed 19/01/2022 21:30:40

Title: [SOLVED] Dialogs Options On/Off while using Script during Dialog?
Post by: Rik_Vargard on Wed 19/01/2022 21:30:40
Hello!

So now I'm wondering if it's possible that a Dialog Option is only shown if Player has that Inventory Item.

Example:
Option 3 "Give him noodles" should only be shown if Player has the Noodles.

For what I know you can't mix "regular scripts" and "dialog scripts" in Dialogs to "option-ON/OFF" an option (based on the "How To Use AGS" tutorials)

Just wondering if there would be an easy fix for this.. or not  :P
Title: Re: Dialogs Options On/Off while using Script during Dialog?
Post by: newwaveburritos on Wed 19/01/2022 22:04:28
Yes, it is possible.  You could put this at the beginning of the dialog in question like any regular script command if you indent the line two spaces.


if (player.HasInventory(iNoodles){
  dialog[1].SetOptionState(3, eOptionOn); //or whichever option "give noodles" is.
}


You can use regular script commands in a dialog if you add two spaces before the line.  You can also use (!player.HasInventory(iNoodles)) if you want something to happen if the player does not have the noodles.
Title: Re: Dialogs Options On/Off while using Script during Dialog?
Post by: Crimson Wizard on Wed 19/01/2022 22:56:48
Quote from: Rik_Vargard on Wed 19/01/2022 21:30:40
For what I know you can't mix "regular scripts" and "dialog scripts" in Dialogs to "option-ON/OFF" an option (based on the "How To Use AGS" tutorials)

You actually can, these tutorials are either mistaken or outdated.

Taking the code newwaveburritos posted above, the mixed code would look like:
Code (ags) Select

  if (player.HasInventory(iNoodles){
option-on 3
  }


notice how "option-on" has no indent, while "if" and brackets have spaces before them.
Title: Re: Dialogs Options On/Off while using Script during Dialog?
Post by: Rik_Vargard on Thu 20/01/2022 12:02:42
Hi! Thank you very much for the reply guys!

Are these two little scripts different possibilities to do the same thing or do they work together somehow?
I tried combining, and using only one and then tried the other one but I keep getting the same error for the line where the IF begins:

"Dialog 5(4): Error (line 4): end of input reached in middle of expression"

In this example option 3 is now option 2 and I used the second script:

Dialog text :

1. Hi
2. Give him noodles
3. Bye

Script :
Code (ags) Select

// Dialog script file
@S  // Dialog startup entry point

  if (player.HasInventory(iNoodles){
option-on 2
  }
return

@1
Jimmy: Hi there.
return

@2
player: Have some noodles.
cJimmy: Thanks!
  player.LoseInventory (iNoodles);
option-off 2
return

@3
player: Bye.
stop


Any ideas?
Title: Re: Dialogs Options On/Off while using Script during Dialog?
Post by: Crimson Wizard on Thu 20/01/2022 12:06:17
You are missing a closing bracket for condition:
Code (ags) Select

  if (player.HasInventory(iNoodles) // here // {


should be
Code (ags) Select

  if (player.HasInventory(iNoodles)) {
Title: Re: Dialogs Options On/Off while using Script during Dialog?
Post by: Rik_Vargard on Thu 20/01/2022 12:13:21
Oh boy, how silly of me, I'll go hide now...  :-[

Thank you so much for your time!  :)
Title: Re: [SOLVED] Dialogs Options On/Off while using Script during Dialog?
Post by: Cassiebsg on Fri 21/01/2022 23:31:25
Here's a tip useful for debugging:

Whenever you see that or similar msg, look for missing brackets, parentheses or a " missing in a previous line, just go up the script until you find the line with the missing " (might not be the exact line where the error was detected).
Title: Re: [SOLVED] Dialogs Options On/Off while using Script during Dialog?
Post by: Rik_Vargard on Sat 22/01/2022 12:59:03
ha Thanks for this useful tip indeed, Cassiebsg! :)