Jump to content


Photo

Using nested if statements


  • Please log in to reply
5 replies to this topic

#1 Sevarus

Sevarus
  • Member
  • 11 posts

Posted 11 May 2006 - 02:52 PM

I'm looking for the IE equivalent of:

If (this happens)
{
	do this
	if (this other thing happens while the previous if is happening)
	{
		 do this too
	}
}

For example, say I'm kicking this NPC out of my party. Depending on what state her quest is in, she'll say different things, but I'm not sure how to go about this.

IF ~Global("EllarynJoined","LOCALS",0)~ THEN BEGIN LeaveGroup
IF ~
   Global("EllarynQuest","GLOBAL",0) GOTO NoQuest
   Global("EllarynQuest","GLOBAL",1) GOTO QuestAccept
   Global("EllarynQuest","GLOBAL",2)~ GOTO QuestFinish
END

This is probably extrememly simple, knowing my luck.

#2 Grim Squeaker

Grim Squeaker

    Fallen

  • Member
  • 1018 posts

Posted 13 May 2006 - 01:35 AM

No can do. It's a limitation of the Infinity Engine. You have to split them into a set of 3 conditions

IF ~A B~ THEN GOTO foo
IF ~A !B~ THEN GOTO bar
IF ~!A~ THEN GOTO fubar

You can get around it slightly if you have a line of dialogue inbetween the two if checks, because then you can have the second set of IFs as the transitions from a second dialogue state. However, that only works if your dialogue fits nicely with that structure.

Edited by Grim Squeaker, 13 May 2006 - 01:36 AM.

"You alone can make my song take flight..."

#3 Azkyroth

Azkyroth
  • Modder
  • 3496 posts

Posted 24 May 2006 - 05:42 PM

It has an OR provision but not an AND provision?

....

"Tyranny is a quiet thing at first, a prim and proper lady pursing her lips and shaking her head disapprovingly, asking, well what were you doing (wearing that dress, walking home at that hour, expressing those inappropriate thoughts) anyway? It's subtle and insidious, disguised as reasonable precautions which become more and more oppressive over time, until our lives are defined by the things we must avoid. She's easy enough to agree with, after all, she's only trying to help -- and yet she's one of the most dangerous influences we face, because if she prevails, it puts the raping, robbing, axe-wielding madmen of the world in complete control. Eventually they'll barely need to wield a thing, all they'll have to do is leer menacingly and we fall all over ourselves trying to placate them." -godlizard


#4 Grim Squeaker

Grim Squeaker

    Fallen

  • Member
  • 1018 posts

Posted 25 May 2006 - 12:37 AM

It has an OR provision but not an AND provision?

....


Well AND is automatic, so there doesn't need to be a trigger for it. A B means A and B. The only reason in the current structure you want AND(X) would be if you could nest logic statements, which you can't.
"You alone can make my song take flight..."

#5 Azkyroth

Azkyroth
  • Modder
  • 3496 posts

Posted 25 May 2006 - 01:58 AM


It has an OR provision but not an AND provision?

....


Well AND is automatic, so there doesn't need to be a trigger for it. A B means A and B. The only reason in the current structure you want AND(X) would be if you could nest logic statements, which you can't.


Good grief. It's amazing a game as great as BG2 could be built on such a shaky foundation (epidemic hardcoding, no nested logical statements, duplicate dialog.tlk entries that would seem to severely undermine the point of even having the file...) When someone with almost no "serious" programming experience can find so many flaws in a program, that's a bad thing x.x

Could I write a better program? No. Probably why I'm not getting paid to do it... ;/

As for the AND(X) I'd prefer to do that with a variable, but I might tend to overuse variable-based approaches...

"Tyranny is a quiet thing at first, a prim and proper lady pursing her lips and shaking her head disapprovingly, asking, well what were you doing (wearing that dress, walking home at that hour, expressing those inappropriate thoughts) anyway? It's subtle and insidious, disguised as reasonable precautions which become more and more oppressive over time, until our lives are defined by the things we must avoid. She's easy enough to agree with, after all, she's only trying to help -- and yet she's one of the most dangerous influences we face, because if she prevails, it puts the raping, robbing, axe-wielding madmen of the world in complete control. Eventually they'll barely need to wield a thing, all they'll have to do is leer menacingly and we fall all over ourselves trying to placate them." -godlizard


#6 Grim Squeaker

Grim Squeaker

    Fallen

  • Member
  • 1018 posts

Posted 25 May 2006 - 02:27 AM

It's true it's not a great system, but it's surprising how much you can achieve with just AND and OR, with no nesting. It's generally quite rare within that you'd reach a situation that can't actually solve using the means provided.

Just be thankful we have OR, otherwise we'd have to have a different transition for each of the arguments (or a different script block for each lovetalk to fire...)
"You alone can make my song take flight..."