Author Topic: Globals out of date for subsequent SAY block?  (Read 696 times)

Offline Bleepbloop

  • Planewalker
  • *****
  • Posts: 7
Globals out of date for subsequent SAY block?
« on: February 10, 2021, 10:16:55 AM »
Hey all. :)

A pattern I'm wanting to use pretty often is to set a global in a transition, then make one or more transitions in the subsequent SAY block depend on it. Example:

Code: [Select]
IF ~~ FirstSayBlock
    SAY ~Some text~

    ++ ~Some text~ DO ~IncrementGlobal("SomeGlobalVariable", "GLOBAL", 1)~ + SecondSayBlock
END

IF ~~ SecondSayBlock
    SAY ~Some text~
    IF ~GlobalLT("SomeGlobalVariable", "GLOBAL", 10)~ THEN GOTO ThirdSayBlock
    IF ~GlobalGT("SomeGlobalVariable", "GLOBAL", 9)~ THEN GOTO FourthSayBlock
END

However, the above doesn't seem to work properly, as I don't get SomeGlobalVariable's new value when the transitions in SecondSayBlock are evaluated.

The only workaround I've found is to spread SecondSayBlock out by using the shorthand chaining syntax. This seems to work:

Code: [Select]
IF ~~ FirstSayBlock
    SAY ~Some text~

    ++ ~Some text~ DO ~IncrementGlobal("SomeGlobalVariable", "GLOBAL", 1)~ + SecondSayBlock
END

IF ~~ SecondSayBlock
    SAY ~Some text~ = ~Some more text~
    IF ~GlobalLT("SomeGlobalVariable", "GLOBAL", 10)~ THEN GOTO ThirdSayBlock
    IF ~GlobalGT("SomeGlobalVariable", "GLOBAL", 9)~ THEN GOTO FourthSayBlock
END

Is there a nicer way to do this?

Offline Argent77

  • Planewalker
  • *****
  • Posts: 187
Re: Globals out of date for subsequent SAY block?
« Reply #1 on: February 11, 2021, 03:08:50 AM »
Script action in dialogs are executed with a delay. Iirc, you need at least two transitions before the variable is updated correctly. However, if you code your mod only for the Enhanced Editions then you can add a flag to the transition to indicate that it should be executed immediately. It should work for all script actions listed in INSTANT.IDS (and possibly some more).

In your example add the keyword "FLAGS" with the respective numeric value (bit 9 = 512) to the reply entry:
Code: [Select]
IF ~~ FirstSayBlock
    SAY ~Some text~
    ++ ~Some text~ DO ~IncrementGlobal("SomeGlobalVariable", "GLOBAL", 1)~ FLAGS 512 + SecondSayBlock
END

IF ~~ SecondSayBlock
    SAY ~Some text~
    IF ~GlobalLT("SomeGlobalVariable", "GLOBAL", 10)~ THEN GOTO ThirdSayBlock
    IF ~GlobalGT("SomeGlobalVariable", "GLOBAL", 9)~ THEN GOTO FourthSayBlock
END


Btw, this board has been pretty quiet for some time. I'd suggest to ask about modding-related topics in the G3 Forums which is more active.

Offline Bleepbloop

  • Planewalker
  • *****
  • Posts: 7
Re: Globals out of date for subsequent SAY block?
« Reply #2 on: February 11, 2021, 03:35:02 AM »
Wow, that is awesome, thank you. I did not expect an outright solution for this. Now to roll up my sleeves and retrofit it into my code. ;D

Btw yeah my mod is for BG2 EE only. And thanks for the tip about the G3 forums.

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: