help with condition script

Started by myname, Mon 21/03/2011 22:12:41

Previous topic - Next topic

myname

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.

Icey

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? :-\

myname

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.

Ryan Timothy B

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:

Code: ags

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.

Khris

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.

myname

Thanks for the response Ryan Timothy but that script still did not work.  I'll figure it out eventually.

myname

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?

Khris

"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:

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

  Display("Congrats %s, you have won!", player_name);  // displays a personal message

myname

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.

SMF spam blocked by CleanTalk