Hello, newbie here. I am trying to learn to script and have been watching this video and got stuck on this particular script. Can anyone give me some insight, please? Thank you.
I’ve been watching a youtube video and I’m currently stuck at 21:17. I think my code is correct, it matches but something is wrong because the goblin, just says the first line over and over.
if(GetLocalInt(oChest,“nUsedTries”) == 0) {
AssignCommand(oChieftain,ActionSpeakString(“Hey! Get away from my chest!”,TALKVOLUME_SHOUT));
SetLocalInt(oChest,“nUseTries”,GetLocalInt(oChest,“nUseTries”)+1);
}
if(GetLocalInt(oChest,“nUsedTries”) == 1) {
AssignCommand(oChieftain,ActionSpeakString(“Back away, This is your last warning!”,TALKVOLUME_SHOUT));
SetLocalInt(oChest,“nUseTries”,GetLocalInt(oChest,“nUseTries”)+1);
}
if(GetLocalInt(oChest,“nUsedTries”) == 2) {
AssignCommand(oChieftain,ActionSpeakString(“Alright, you asked for it!”,TALKVOLUME_SHOUT));
@Aurelius I think I realized now that your script actually worked when you had fixed the variable name, right? So my own script was quite unnecessary, I guess. I read your post too fast last night, so sorry about that. In any case, @Philos way of doing it is the best. I know @kevL_s has pointed this out many times to me, to use constants at the beginning of the script to avoid spelling mistakes.
Actually, I think your script was fine. i.e. It required “else if”, otherwise, it kept firing the next “if” because it was always ready to fire due to the addition.
@Lance_Botelle - I didn’t mean mean my didn’t work. I think it would have worked just as fine as Philos’ and Aurelius’ own script, just that it was unnecessary since Aurelius figured out what was wrong in the script.
I think the script requires the “else if”. Otherwise, the var sets and allows the next condition to fire too. I.e. If 0 (zero) is passed, the first condition is fired, which adds 1 to the var, now 1, which passes at the next check. So that also fires, adds one to the var, now 2, which fires the last condition too. Your script is the only one that does not fire all conditions if 0 is passed.
const string USES = "nUsedTries";
void main()
{
object oChieftain = GetNearestObjectByTag("ChiefSnaggleTooth");
if (GetIsObjectValid(oChieftain))
{
string bark;
switch (GetLocalInt(OBJECT_SELF, USES))
{
default:
bark = "Alright, you asked for it!";
// todo: If chieftan is not already in combat
// - set to hostile faction
// - call DetermineCombatRound() vs GetLastUsedBy()
break;
case 0:
SetLocalInt(OBJECT_SELF, USES, 1);
bark = "Hey! Get away from my chest!";
// todo: turn chieftan to face GetLastUsedBy()
break;
case 1:
SetLocalInt(OBJECT_SELF, USES, 2);
bark = "Back away, This is your last warning!";
// todo: turn chieftan to face GetLastUsedBy() and emote vigorously
break;
}
AssignCommand(oChieftain, ActionSpeakString(bark, TALKVOLUME_SHOUT));
}
}