conditional code help please(SOLVED TY)

Started by proskiier, Sun 18/11/2007 05:26:48

Previous topic - Next topic

proskiier

code:
  // script for Object 1: Talk to object
bool talkto = false;

if talkto == false then{
cStrangekid.Say ("I can't thank you enough for getting me out of that hole.");
cStrangekid.Say ("Here take this, I found it hidden in the hole, but you can have it.");
cEgo.AddInventory(iTv);
talkto = true;
else
cStrangekid.Say ("Thanks again man.");
talkto=false;
}
}

essentially you talk to the kid and if you have already talked to him, he says the second part in the if statement, and you cant get the tvs more than once

monkey0506

#1
First off, you have to enclose the condition of the if-statement (in AGS). Also AGS doesn't require the then word as it's already implied you're going to be doing this anyway. And finally, you just need to check your braces.
// room script
bool talkto = false;

  // script for Object 1: Talk to object
// moved talkto variable to top of room script (see Gilbot's post below)

if (talkto == false) {
  cStrangekid.Say ("I can't thank you enough for getting me out of that hole.");
  cStrangekid.Say ("Here take this, I found it hidden in the hole, but you can have it.");
  cEgo.AddInventory(iTv);
  talkto = true;
  }
else {
  cStrangekid.Say ("Thanks again man.");
  // removed talkto = false (see Ashen's post below)
  // notice that I removed one brace here, it belonged before the beginning of the else-clause
}
Indentation helps you to better visualize the way your braces are set up so you can match them better. ;)

Also for future reference you can use the
[ code ]
and
[ /code ]
tags (without the spaces) for enclosing code in the forums like this:

Code: ags
// This is some code!
int a = 10;


Edit (following Gilbot's post) Yes, that is, of course, also true. Heh. Now object interactions...those functions are placed in the room script I believe, yes?

Gilbert

Also, since the "talkto" variable is declared inside of the "Talk to Objects" function. it would be reset to false each time the interaction starts.

You need to move that "bool talkto = false;"  outside of the function (on the top of the script maybe).

Ashen

Also also, you might want to get rid of the talkto = false; in the else condition. With that there, if you talk to the Object (?) a third time, it'll run the (talkto == false) code again (followed by the else, followed by the false, followed by ... and so on).
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk