int variables, basic scripting

Started by Krantz, Wed 24/01/2007 00:48:10

Previous topic - Next topic

Krantz

(Warning:Ã,  I am a NOVICE!)

I have an object (a refrigerator) with a door that opens and closes.Ã,  After many attempts, the only way I could make the door animate "open" when the player interacts with it the first time, make it "close," the second time, "open" the next time, etc., was to turn to scripting and an int variable.Ã,  (That seems like such a basic action that there must be a way to do it without scripting which would be more appropriate for a beginner like me, but I cannot figure it out.)Ã,  But anyway I got that to work. My next problem is how to have the player "find" something in the fridge (display a message that says "You find a blue cup in the fridge and take it," and still be able to show the fridge door open and close.Ã,  After many attempts, I can make the player open the fridge door, see the message, get the inventory item, and shut the fridge door again --- on the FIRST interaction.Ã,  But the next time the player interacts with the fridge (where I would want a message to say "There is nothing else of interest in the fridge") - becomes eight different kinds of screwed up.Ã,  I've been guessing at my scripting, trying different variations.Ã,  Here's what I have (needless to say, this doesn't work):

// script for Object 0: Interact object
if (fridge == 0) {object[0].Animate(0,0);}

{DisplayMessage(0);}

{player.AddInventory(inventory[3]);}

{object[0].Animate(1,0);}

if (fridge == 1) {object[0].Animate(0,0);}
{DisplayMessage(1);}

{object[0].Animate(1,0);}

if (fridge < 1) {fridge +=1;}


Any help would be hugely appreciated - I've spent hours on this, and it's such a simple action!

Gilbert

Something like this?

Code: ags

// script for Object 0: Interact object
if (fridge == 0) {
  object[0].Animate(0,0);
  DisplayMessage(0);
  player.AddInventory(inventory[3]);
  object[0].Animate(1,0);
  fridge=1;
  }

 
if (fridge == 1) {
  object[0].Animate(0,0);
  DisplayMessage(1);
  object[0].Animate(1,0);
  }


strazer

Gil, never thought you'd make that mistake: ;)

Quote from: Gilbot V7000a on Wed 24/01/2007 01:19:30
Code: ags
fridge=1;
  }


if (fridge == 1) {

Since you've just changed "fridge" to 1 in the first condition, this would always run the second condition directly after the first.

Krantz, also change

if (fridge == 1) {

to

else if (fridge == 1) {

so it skips the second condition after it has run the first.

Krantz

Thanks to both of you!  Problem solved.  Now there's no limit to what I can accomplish.  Power, power, POWER!!! Mwah-ha-ha-haha...

Khris

For the closing brace, I use the indentation of the if-line (none in this case). That's personal preference, but I think it looks cleaner.

If you're curious, here's the sequence of interaction events for the above code:

SMF spam blocked by CleanTalk