[SOLVED] Dialogs Options On/Off while using Script during Dialog?

Started by Rik_Vargard, Wed 19/01/2022 21:30:40

Previous topic - Next topic

Rik_Vargard

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

newwaveburritos

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.

Code: ags

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.

Crimson Wizard

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

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


notice how "option-on" has no indent, while "if" and brackets have spaces before them.

Rik_Vargard

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

// 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?

Crimson Wizard

You are missing a closing bracket for condition:
Code: ags

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


should be
Code: ags

  if (player.HasInventory(iNoodles)) {

Rik_Vargard

Oh boy, how silly of me, I'll go hide now...  :-[

Thank you so much for your time!  :)

Cassiebsg

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).
There are those who believe that life here began out there...

Rik_Vargard


SMF spam blocked by CleanTalk