A quick script related question

I noticed a thing in one of my scripts that didn’t work. I was a bit suprised by this and changed it so now it works. I just thought it would work, but there’s probably a logical explanation for this. What I had written was this:

if(!GetJournalEntry("q_newworlds", oPC1) == 21) return;

I changed it to:

if(GetJournalEntry("q_newworlds", oPC1) < 21) return;

Maybe the correct way to have written it would have been:

if(GetJournalEntry("q_newworlds", oPC1) != 21) return;

! has priority over ==, so your first line is interpreted by the compiler as :
if ( (!GetJournalEntry(“q_newworlds”, oPC1)) == 21) return;

If the quest is started, (!GetJournalEntry(“q_newworlds”, oPC1) returns 0 (NOT any positive value),

If the quest is not started yet, it returns 1 (NOT 0).

Neither 0 nor 1 being equal to 21, it’s always FALSE whatever the quest status.

To match your first idea the correct syntax would be :
if (!(GetJournalEntry("q_newworlds, oPC1) == 21)) return;

if(GetJournalEntry(“q_newworlds”, oPC1) != 21) return;` is ok too.

2 Likes

Hmmm. Ok. This with the “!” is still something I’ve never fully grasped, cause sometimes it seems to work and othertimes not. But thinking about it, I guess with a function like if(!GetIsPC(oPC)) return; the game just checks if it’s true or false, and that’s the way it did here too. I didn’t know you could put a “!” in front of the function like that, before the parenthesis.

@Claudius33 probly meant this

if (!(GetJournalEntry("q_newworlds", oPC1) == 21)) return;

but yeah id stick w/ standard syntax

if (GetJournalEntry("q_newworlds", oPC1) != 21) return;

 
assuming 21 is the highest value of the quest… else use the less-than operator – or something, depends what you’ve got going …

1 Like

Well, that actually makes more sense to me, that you need another paranthesis around the whole thing. I’ve never seen a “!” outside a paranthases before.

Oops sorry, unfinished copy/paste. Kev is of course right, I meant that.

1 Like