(Solved) Changing variables in dialog

Started by viktor, Fri 04/12/2020 06:45:48

Previous topic - Next topic

viktor

Hello,

I'm trying to change a variable once a certain line of dialog is spoken.

the variable is defined in the global script header as shirt_var=0;

Then I put this in to the dialog:
Code: ags
@2
run-script 1
Option-off 2
return


and this in to the global script:
Code: ags
function dialog_request(int param) {
  if (param == 1) {
    player.Say("It worked.");
    shirt_var=1;
  }
}


The thing is the script runs. My player says "It worked" but the variable doesn't change.
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

Crimson Wizard

#1
Two questions: how and where exactly have you declared the variable, and how do you test that variable changed or not?

If you forgot to add "import" keyword for the variable declaration in the header, then this will add a separate variable in every script module, including rooms. Meaning, instead of having 1 variable belonging to global script you will instead have some amount of duplicate variables per script (each having its own value).

"Import" keyword is important as it tells that variable is "somewhere else", so you can normally create it in one place (usually - in script body), but tell everyone else that it exists.

For more information about import/export of variables please see this article of the manual:
https://adventuregamestudio.github.io/ags-manual/ScriptKeywords.html#import

I could swear there's a more clear explanation somewhere, but I could not find it, so maybe it was my imagination... Some basic things are still difficult to find in the manual sometimes.

PS.
It may be easier for starters to create variables using Global Variables panel in the editor instead of doing this by hand.

PPS.
Also just in case: when in dialog script you do not have to do "run-script" to change variables, as you can use any regular script commands right in the dialog, if preceded by at least 1 space.

viktor

I didn't really understand the "Import" keyword but I used the Global Variables and inserted the code directly in to the dialogue and now it works. Thank you :D.
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

SMF spam blocked by CleanTalk