This is my code:
int Eat_Cereal = 0;
if (Eat_Cereal == 0) {
oCereal.Graphic = 69;
cHomer.Say ("UHHHMMMM. Haaaiiirrryyyy...");
cHomer.Say ("***DROOL***");
Eat_Cereal++ ;
}
if (Eat_Cereal == 1) {
cHomer.Say ("Ohhh. The Bowl is Empty!");
}
I want Homer to eat the Cereal, and when he eats it, it basically empties the bowl. So the next time he tries to eat it, it has a different interaction on it. But this script above doesn't work. It keeps Doing everything, no matter what.
Anything visibly wrong with this code?
Where did you put the code? And are you declaring that int inside or outside of a function?
I had a similar problem too, and I solved it by declaring the second function as "else if".
In other words:
if (Eat_Cereal == 0) {
oCereal.Graphic = 69;
cHomer.Say ("UHHHMMMM. Haaaiiirrryyyy...");
cHomer.Say ("***DROOL***");
Eat_Cereal++ ;
}
else if (Eat_Cereal == 1) {
cHomer.Say ("Ohhh. The Bowl is Empty!");
}
Not sure if that's the problem you're facing though...
The else if didn't work either. It just keeps displaying the first message and not the second one instead.
What I did was, in the interaction editor for the object, I did a conditional where if the player character was Homer, it would run a script. Thats where I put the script.
Thanks anyway. Any other suggestions?
I see no visible problems with the code (aside from the use of dual ifs instead of if/else-if). See...the problem with the original code is that you update the Eat_Cereal variable in the first statement so by the time the second is run Eat_Cereal is already set to 1, thus both statements would be run the first time, and the second every consecutive time.
You said at first that he was doing everything, but now you say it's only running the first message...but yet you act as if nothing has changed...What I'm envisioning is this...
You've declared the Eat_Cereal variable within your conditional function haven't you? i.e., the line such as:
int Eat_Cereal = 0;
Is actually inside the function, am I right? This would mean the variable is destroyed at the end of the function, and recreated (and therefore reinitialized) at the start of the function.
This would explain the "it keeps doing everything" status of the if-if structure, and the "it just keeps displaying the first" status of the if-else structure.
So basically you just need to move the variable declaration outside the function.
If you've declared the variable outside the function feel free to correct me though.
Sorry to keep pimping my modules, by they were made to solve these kind of problems. Import MultiResponse (http://ssh.me.uk/moddoc/MultiResponse).
int state=Multi.Say(cHomer, "UHHHMMMM. Haaaiiirrryyyy...>Ohhh. The Bowl is Empty!");
if (state==0) {
oCereal.Graphic = 69;
cHomer.Say ("***DROOL***");
}
Thanks SSH, but Monkey's workaround worked great! Thanks guys.