function hTopDrawer_AnyClick()
{
if (Verbs.UsedAction(eGA_WalkTo)) {
}else if(Verbs.UsedAction(eGA_Pull)) {
player.Say("Try Opening it.");
}else if(Verbs.UsedAction(eGA_Push)) {
player.Say("I don't need to Push that");
}else if(Verbs.UsedAction(eGA_Open)) {
player.Say("Okay.");
sDrawer.Play();
player.Say("There was a Fork in the Drawer.");
player.AddInventory(iFork);
Fork1 = true;
}if (Fork1 == true){
player.Say("Nothing Else.");
}else if(Verbs.UsedAction(eGA_Close)) {
player.Say("Already closed.");
}
}
If I open the drawer again it just gives me the item again. However if I right click it says "nothing else"
Try something like this:
else if(Verbs.UsedAction(eGA_Open)) {
if (Fork1 == true){
player.Say("Nothing Else.");
return;
}
player.Say("Okay.");
sDrawer.Play();
player.Say("There was a Fork in the Drawer.");
player.AddInventory(iFork);
Fork1 = true;
worked perfectly thanks!. didn't know about *return*
just for future reference, you could also use a Game.DoOnceOnly. That would save you for creating a variable just for the effect, or you could check if the player has the item in inventory (though if he lost it when using it and you didn't want him to get a new fork, then the first option it best. ;)
Quote from: Jojowl80 on Sun 20/09/2020 02:17:51
worked perfectly thanks!. didn't know about *return*
No worries. "Return" is a pretty important tool so I'm glad you have it now. It will save you many headaches in coding!
You were pretty close, but you had the Fork check in the Verbs check level as opposed to inside the eGA_Open block.
I'm going to go out on a limb and suggest that using proper indentation will help immensely with understanding the involved logic here:
function hTopDrawer_AnyClick() {
if (Verbs.UsedAction(eGA_WalkTo)) {
}
else if (Verbs.UsedAction(eGA_Pull)) {
player.Say("Try Opening it.");
}
else if (Verbs.UsedAction(eGA_Push)) {
player.Say("I don't need to Push that");
}
else if (Verbs.UsedAction(eGA_Open)) {
// all this is inside the eGA_Open block, as indicated by the curly braces AND INDENTATION
if (Fork1 == true) {
player.Say("Nothing Else.");
} else {
player.Say("Okay.");
sDrawer.Play();
player.Say("There was a Fork in the Drawer.");
player.AddInventory(iFork);
Fork1 = true;
}
}
else if (Verbs.UsedAction(eGA_Close)) {
player.Say("Already closed.");
}
else Verbs.Unhandled(); // deal with remaining verbs!
}
See how the visual aspect clarifies instantly what's happening here?