Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: myname on Mon 21/03/2011 22:12:41

Title: help with condition script
Post by: myname on Mon 21/03/2011 22:12:41
I have looked over the tutorial on conditions and if's and think it just might be over my head at this point.

This is my script

function owatercooler_Interact()
{
player.Say("Don't know why I would need that now.");
if (dJasper1)
  {
    cNancy.Say("What the hell do you think you are doing?");
       player.Say("*sigh*");     
    }
}

Basically I want for the player to try o pick up the water cooler and the "Don't know why I would need that now." pops up.  Then after conversing with Jasper he goes to pick it up again and that triggers a dialog with Nancy.  Thanks for anyone who can help.  Much appreciated.
Title: Re: help with condition script
Post by: Icey on Mon 21/03/2011 22:59:55
So you want the play to interact with the cooler then talk with jasper then start a dialog with nancy.

Do you think you can explain it a bit more? :-\
Title: Re: help with condition script
Post by: myname on Tue 22/03/2011 00:50:19
Sorry for not being more descriptive...My goal was not to have the water cooler be an item that the player could pick up into he realizes he needs it (dialog with Jasper).  Then when the player goes to pick up the water cooler again a dialog starts with Nancy.  Thanks for responding.
Title: Re: help with condition script
Post by: Ryan Timothy B on Tue 22/03/2011 01:14:46
Let's see if I have this correct..
dJasper1 is a bool that you're setting to true once you've talked to Jasper, and not the dialog name itself, correct? In that case, something like this, I imagine:


function owatercooler_Interact()
{
  if (dJasper1)
  {
    cNancy.Say("What the hell do you think you are doing?");
    player.Say("*sigh*");     
  }
  else
  {
    player.Say("Don't know why I would need that now.");
  }
}



If you've talked to Jasper, (dJasper1 == true), Nancy yells at you and you respond with a sigh. And that will run every time you interact with the cooler after talking to Jasper.

Otherwise (else).

The player will tell you he doesn't know that he even needs it, and he'll say this every time you interact with the cooler before talking to Jasper.




Conditions are pretty easy once you start looking at them logically.
if (theVariable == 10) doThis();
  else if (theVariable > 10) doThat();
    else doWhatever();

For that line of code, you're checking an int variable named 'theVariable' (an 'int' is a variable that stores numbers. Anywhere between â€"2,147,483,648 to 2,147,483,647). It'll run in the order you read it, from top to bottom.

- If theVariable is equal to 10, it will run the function: doThis() and stop there without proceeding to the else's.
- If theVariable wasn't equal to 10, it will run the next else in line which is checking if theVariable is higher than 10. If it is, it'll run the function doThat() and stop there.
- If theVariable wasn't equal to 10 and wasn't higher than 10, it will run the final else (which means theVariable is lower and not equal to 10) it will run the doWhatever() function.
Title: Re: help with condition script
Post by: Khris on Tue 22/03/2011 12:19:21
Just to be clear, you have to create a global variable and set that to true within the dialog.
You can't put the dialog's name in a condition like that.

What "if" does is evaluate the expression inside (), then execute the lines inside {} if the value is true / not 0.
Title: Re: help with condition script
Post by: myname on Sun 27/03/2011 06:03:41
Thanks for the response Ryan Timothy but that script still did not work.  I'll figure it out eventually.
Title: Re: help with condition script
Post by: myname on Sun 27/03/2011 16:46:31
Thanks for responding Khris, I am kind of confused about creating global variables and "if's".  Do you know what part of the game help index has info in this?
Title: Re: help with condition script
Post by: Khris on Sun 27/03/2011 18:28:23
"if" is explained here: http://www.adventuregamestudio.co.uk/manual/ifelsestatements.htm
That doesn't go much deeper than what we discussed here though.

Global variables are variables that can be accessed (i.e. read and written) from every script. In the Global variables pane in AGS'S project tree, you can add one by specifying its name, type and initial value.

An example would be a variable called player_name and of type String which holds "Player 1" at the beginning.
Later, at any point during the game, you can now overwrite the contents of that or display it:

  player_name = NameInput.Text;   // NameInput is a text field on a GUI

  Display("Congrats %s, you have won!", player_name);  // displays a personal message
Title: Re: help with condition script
Post by: myname on Tue 29/03/2011 00:25:19
Thanks Khris, I think this might be a little out of my league right now.  I'm going to take some time and watch tutorials before anymore scripting.