At a given in-game time, I want my companion NPC to make a random comment. This is my current code, which isn't working.
Spoiler begin gamemode
; Name the variable.
short ValRandomComment
; FIRST, the time must be 12.00, AND the event must not have happened already.
; THEN, the NPC says the comment.
; THEN, the variable increments, to ensure that it won't keep firing after the NPC has spoken.
if GameHour == 12 && ValRandomComment == 0
cmValREF.SayTo player ValMudcrabs00 1
set ValRandomComment to 1
; ...but since I want this to happen again, at 13.00 (IF the NPC has spoken) the variable resets to zero.
else if GameHour == 13 && ValRandomComment == 1
set ValRandomComment to 0
endif
endif
end
I have a feeling I'm missing something incredibly obvious-- either in my syntax, my understanding of if/else if, or the way GameHour needs to be used. Or, okay, possibly all three.
Checking via console verifies that I'm not even getting the variable to correctly increment, presumably since the SayTo isn't triggering. I've managed to make it work with trigger zones, rather than a given time of day, which makes me feel a shade less incompetent.
I'm surprised your script even saves properly. I see a few potential problems:
1. Most likely culprit: GameHour actually returns a float value, even though it appears to be a short. The CS wiki mentions this on the page on time variables. So GameHour will never match 12 or 13; it will always be 11.997, 12.00123, whatever. Even if it were a short, you should make the conditions be e.g. "GameHour > 12" instead of "GameHour == 12", since it's possible to skip over several hours while sleeping, etc without triggering this gamemode block.
2. That "else if" should be "elseif".
3. Is "cmValRef" defined anywhere? I assume this is what you've named the instance of your companion in the CS, but make sure that's true.
4. Your comment in the script don't match what it's actually doing. Even if the code worked properly, it would fire at noon, then reset the flag at 1pm, then fire the comment again on noon the next day, etc. But the comments imply that you want a new comment every hour.
5. Is this script attached to the companion? To a quest? If it's a quest, is the quest running?
How about this instead:
begin gamemodefloat lastCommentTimeif (GameHour > (lastCommentTime + 1)) cmValREF.SayTo player ValMudcrabs00 1 set lastCommentTime to GameHourendif end
Viola, one comment per hour, as long as "cmValREF" points to somebody real.