Aller au contenu

Photo

ShowPopup showing a popup even if script is exited before its call


  • Veuillez vous connecter pour répondre
12 réponses à ce sujet

#1
NSIBystander

NSIBystander
  • Members
  • 18 messages
Hi, I was wondering if anyone else had seen this issue.  I'm using ShowPopup as a dialog with four buttons in an add-on of mine, and it works fine initially.  But my script sets a flag to prevent going into the script again once it is run through the first time, and even though it can't get to the point where ShowPopup is called, it still shows the popup again when the game is loaded after having gone through the script once.

Here's a snippet of the relevant code:

----------------------------------------------------------
void main()
{
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_IMPROVED_ITEM_FLAG) == TRUE)
        return;

    // Get the player's Origin to determine which improved item to give
    object oHero = GetHero();
    int nRace = GetCreatureRacialType(oHero);
    int nBackground = GetPlayerBackground(oHero);

    ShowPopup(1205465333, 15700);

    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch (nEventType)
    {
        case EVENT_TYPE_POPUP_RESULT:
        {
----------------------------------------------------------

At the end of the script, regardless of what happens in the script, it sets that DIM_ALL_IMPROVED_ITEM_FLAG to TRUE so that it never goes into the script again.  But when I save the game and then load the game, it displays the popup dialog again (and none of the buttons do anything this time through).

Does anyone have any ideas?
Thanks.

#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
I haven't experimented much with scripting yet but maybe this will shed some light on this issue - http://social.biowar...x/387167#411925



Apparently, there is a distinction between the Main Flag and a Defined Flag, though at present I have no idea what that is. I am assuming you will know since you are using them :)

#3
NSIBystander

NSIBystander
  • Members
  • 18 messages
Thanks for the response. It is a Main Flag, so that shouldn't be an issue.



The script was also working fine and not doing anything on subsequent loads prior to me adding in the Popup dialog. And even now it seems as though the only thing it does is display the popup. I can put stuff before the ShowPopup call but after the flag check that doesn't occur, but the Popup still appears.

#4
Sunjammer

Sunjammer
  • Members
  • 925 messages

NSIBystander wrote...

The script was also working fine and not doing anything on subsequent loads prior to me adding in the Popup dialog. And even now it seems as though the only thing it does is display the popup. I can put stuff before the ShowPopup call but after the flag check that doesn't occur, but the Popup still appears.

If this is your module event script (since that his where EVENT_TYPE_POPUP_RESULT is sent) then you need to specify which event should create the popup.  The lack of a EVENT_TYPE_* guard condition means every event sent to the module will attempt to open a popup.  It also means you are probably going to break your module if the plot flag is ever set as it will pre-emptively abort your module script.

If this is not your module event script then it won't receive EVENT_TYPE_POPUP_RESULT which probably means (although I can't see it in the snippet, that the plot flag is never being raised.  Therefore every time you trigger that script it will call ShowPopup.

Knowning the full script and where it has been assigned would all us to give you a better idea where the problem is.

#5
NSIBystander

NSIBystander
  • Members
  • 18 messages

Sunjammer wrote...

If this is your module event script (since that his where EVENT_TYPE_POPUP_RESULT is sent) then you need to specify which event should create the popup.  The lack of a EVENT_TYPE_*
guard condition means every event sent to the module will attempt to
open a popup.  It also means you are probably going to break your
module if the plot flag is ever set as it will pre-emptively abort your
module script.

If this is not your module event script then it won't receive EVENT_TYPE_POPUP_RESULT
which probably means (although I can't see it in the snippet, that the
plot flag is never being raised.  Therefore every time you trigger that
script it will call ShowPopup.

Knowning the full script and where it has been assigned would all us to give you a better idea where the problem is.


This is indeed my module event script.  I'm at work right now so I don't have access to the full script, but once I get home tonight I can upload that.

The intention is to show the popup the first time the add-in is loaded, have the user select one of the four buttons, and to give the character two items based on their origin and based on which of the four buttons were pressed.  After giving the items, the DIM_ALL_IMPROVED_ITEM_FLAG is set to TRUE so that it won't go into the script again.

Prior to having the popup, I was doing it pretty much identically to how weriKK suggested in his custom item blog (http://social.biowar.../5339/blog/576/).  When I added the popup, I changed the case statement from triggering on EVENT_TYPE_MODULE_LOAD and EVENT_TYPE_CHARGEN_END to EVENT_TYPE_POPUP_RESULT so that I could get the information about which button was selected.

Modifié par NSIBystander, 09 décembre 2009 - 10:05 .


#6
NSIBystander

NSIBystander
  • Members
  • 18 messages

Sunjammer wrote...

Knowning the full script and where it has been assigned would all us to give you a better idea where the problem is.


Now that I'm home I can provide you with the full script:

#include "utility_h"
#include "wrappers_h"
#include "plt_dim_improved_item_plot"

void main()
{
    // Stop script if we've already given the items
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_IMPROVED_ITEM_FLAG) == TRUE)
        return;

    // Get the player's Origin to determine which improved item to give                    
    object oHero = GetHero();
    int nRace = GetCreatureRacialType(oHero);
    int nBackground = GetPlayerBackground(oHero);

    ShowPopup(1205465333, 15700);

    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch (nEventType)
    {
        // Watch for when the player clicks on one of the popup's buttons
        case EVENT_TYPE_POPUP_RESULT:
        {
            int nButton = GetEventInteger(ev, 1);

            // Add the improved Warden's Oath amulet
            if (nButton == 2) UT_AddItemToInventory(R"dim_imp_wardensoath_low.uti", 1);
            if (nButton == 3) UT_AddItemToInventory(R"dim_imp_wardensoath.uti", 1);
            if (nButton == 4) UT_AddItemToInventory(R"dim_imp_wardensoath_high.uti", 1);

            // If the player is a Mage, award the improved Ring of Study
            if (nBackground == 4)
            {
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_ringofstudy_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_ringofstudy.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_ringofstudy_high.uti", 1);
            }

            // If the player is a City Elf, award the improved Wedding Ring
            if (nBackground == 3)
            {
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_weddingring_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_weddingring.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_weddingring_high.uti", 1);
            }

            // If the player is a Dalish Elf, award the improved Keeper's Ring
            if (nBackground == 1)
            {
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_keepersring_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_keepersring.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_keepersring_high.uti", 1);
            }

            // If the player is a Dwarf Commoner, award the improved Aeducan Mace
            if (nBackground == 2)
            {
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_aeducanmace_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_aeducanmace.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_aeducanmace_high.uti", 1);
            }

            // If the player is a Dwarf Noble, award the improved Aeducan Signet Ring
            if (nBackground == 5 && nRace == 1)
            {
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_aeducanring_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_aeducanring.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_aeducanring_high.uti", 1);
            }

            // If the player is a Human Noble, award the improved Family Sword
            if (nBackground == 5 && nRace == 3)
            {
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_familysword_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_familysword.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_familysword_high.uti", 1);
            }

            // Set the completion flag as true so that it doesn't go into the script again
            WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_IMPROVED_ITEM_FLAG, TRUE);

            break;
        }
        default:
            break;
    }
}

The
DIM_ALL_IMPROVED_ITEM_FLAG
is a Main Flag with its default value not set.

#7
NSIBystander

NSIBystander
  • Members
  • 18 messages
Ok, a good amount of logging enabled me to figure out the problem.  It was loading portions of the script (including the popup) before it got the information on the flags to know that it wasn't supposed to load the script anymore.

So I reworked the script pretty heavily (and cleaned it up a bit as well) and it seems to work now.  Thanks a bunch for the assistance and information on the EVENT_TYPE_* conditions.

Here's the new script for comparison:

#include "utility_h"
#include "wrappers_h"
#include "plt_dim_improved_item_plot"

void main()
{  
    // Stop script if we've already given the items
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG) == TRUE)
        return;

    int nButton = 0;
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_4) == TRUE) nButton = 4;
    else if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_3) == TRUE) nButton = 3;
    else if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_2) == TRUE) nButton = 2;
    else if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_1) == TRUE) nButton = 1;

    if (nButton > 0)
    {
        // Get the player's Origin to determine which improved item to give                    
        object oHero = GetHero();
        int nRace = GetCreatureRacialType(oHero);
        int nBackground = GetPlayerBackground(oHero);

        // Add the improved Warden's Oath amulet
        if (nButton == 2) UT_AddItemToInventory(R"dim_imp_wardensoath_low.uti", 1);
        if (nButton == 3) UT_AddItemToInventory(R"dim_imp_wardensoath.uti", 1);
        if (nButton == 4) UT_AddItemToInventory(R"dim_imp_wardensoath_high.uti", 1);
                                                                              
        switch(nBackground)
        {
            case 1:  // If the player is a Dalish Elf, add the improved Keeper's Ring
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_keepersring_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_keepersring.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_keepersring_high.uti", 1);
                break;
            case 2:  // If the player is a Dwarf Commoner, add the improved Aeducan Mace 
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_aeducanmace_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_aeducanmace.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_aeducanmace_high.uti", 1);
                break;
            case 3:  // If the player is a City Elf, add the improved Wedding Ring 
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_weddingring_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_weddingring.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_weddingring_high.uti", 1);
                break;
            case 4:  // If the player is a Circle Mage, add the improved Ring of Study  
                if (nButton == 2) UT_AddItemToInventory(R"dim_imp_ringofstudy_low.uti", 1);
                if (nButton == 3) UT_AddItemToInventory(R"dim_imp_ringofstudy.uti", 1);
                if (nButton == 4) UT_AddItemToInventory(R"dim_imp_ringofstudy_high.uti", 1);
                break;
            case 5:  
                if (nRace == 1)  // If the player is a Dwarf Noble, add the improved Aeducan Signet Ring
                {
                    if (nButton == 2) UT_AddItemToInventory(R"dim_imp_aeducanring_low.uti", 1);
                    if (nButton == 3) UT_AddItemToInventory(R"dim_imp_aeducanring.uti", 1);
                    if (nButton == 4) UT_AddItemToInventory(R"dim_imp_aeducanring_high.uti", 1);
                }
                else if (nRace == 3)  // If the player is a Human Noble, add the improved Family Sword
                {
                    if (nButton == 2) UT_AddItemToInventory(R"dim_imp_familysword_low.uti", 1);
                    if (nButton == 3) UT_AddItemToInventory(R"dim_imp_familysword.uti", 1);
                    if (nButton == 4) UT_AddItemToInventory(R"dim_imp_familysword_high.uti", 1);
                }
                break;
            default:   
                PrintToLog("Error: dim_improved_item_handler:  No valid origin");
                break;     
        }

        // Set the completion flag as true so that it doesn't go into the script again
        WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG, TRUE);
        return;
    }
    
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);

    switch (nEventType)
    {
        case EVENT_TYPE_POPUP_RESULT:
        {                                                          
            int nButton = GetEventInteger(ev, 1);
            if (nButton == 1)
                WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_1, TRUE);
            else if (nButton == 2)
                WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_2, TRUE);
            else if (nButton == 3)
                WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_3, TRUE);
            else if (nButton == 4)
                WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_BUTTON_RESULT_4, TRUE);
            break;
        }
        case EVENT_TYPE_MODULE_LOAD:
        case EVENT_TYPE_CHARGEN_END:
        {
            ShowPopup(1205465333, 15700);
            break;
        }
        default:
            PrintToLog("Error: dim_improved_item_handler:  No applicable event");
            break;
    }
}


#8
FalloutBoy

FalloutBoy
  • Members
  • 580 messages
Wait, so you replaced module_core with this? That is very bad.

void main()
{  
    // Stop script if we've already given the items
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG) == TRUE)
        return;

If that is a module event handler, the code I pasted is going to prevent any events from happening. Even if you get your popup working, your module is going to have weird behavior. Put the popup business inside a function and call the function when you get a EVENT_TYPE_MODULE_START event.

There are templates you can use for the various event handlers in the game. That little window to the right of your code editor that shows you the list of all the functions, at the top of that window, click on the button that looks like a piece of paper. Select "Custom module events".

Modifié par FalloutBoy, 10 décembre 2009 - 04:51 .


#9
NSIBystander

NSIBystander
  • Members
  • 18 messages

FalloutBoy wrote...

Wait, so you replaced module_core with this? That is very bad.

void main()
{  
    // Stop script if we've already given the items
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG) == TRUE)
        return;

If that is a module event handler, the code I pasted is going to prevent any events from happening. Even if you get your popup working, your module is going to have weird behavior. Put the popup business inside a function and call the function when you get a EVENT_TYPE_MODULE_START event.

There are templates you can use for the various event handlers in the game. That little window to the right of your code editor that shows you the list of all the functions, at the top of that window, click on the button that looks like a piece of paper. Select "Custom module events".


Don't worry, I didn't replace or overwrite module_core or any other game files.  It's in it's own script that runs in the add-on.  It just stops that specific add-in from running if the add-in has already done what it is meant to do (which is just to give the character some items).

#10
Sunjammer

Sunjammer
  • Members
  • 925 messages
Eep! That is a script and a half. It seems to me that you could wrap most of the top code in a function and call it from the EVENT_TYPE_POPUP_RESULT case passing in nButton as a parameter. This would avoid both your problem with the guard condition (which could be relocated to the EVENT_TYPE_CHARGEN_END case so as not to interfere with any other event) and remove the need for a plot flag for each button.

If you are interested in that approach let me know and I'll mock it up.

#11
NSIBystander

NSIBystander
  • Members
  • 18 messages

Sunjammer wrote...

Eep! That is a script and a half. It seems to me that you could wrap most of the top code in a function and call it from the EVENT_TYPE_POPUP_RESULT case passing in nButton as a parameter. This would avoid both your problem with the guard condition (which could be relocated to the EVENT_TYPE_CHARGEN_END case so as not to interfere with any other event) and remove the need for a plot flag for each button.
If you are interested in that approach let me know and I'll mock it up.


Sorry for the delay, it's been a busy few days.  That's a good idea and most of it makes a lot of sense to me.  Though could you clarify what you mean when you say the guard condition could be relocated so it doesn't interfere?
Thanks.

#12
Sunjammer

Sunjammer
  • Members
  • 925 messages
Your guard condition:

    // Stop script if we've already given the items
    if (WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG) == TRUE)
        return;

currently prevents all module event processing by your add-in once it has set. While this is probably fine in your particular case because this script is for an add in and once the Player has their items its job is done.  However you may have noticed it raised a few question marks in this thread.

As you only need it to prevent the calls to ShowPopup and when processing the EVENT_TYPE_POPUP_RESULT so normally we would pace the check the guard conditions in those cases. This would allow you to use the other module events if you wanted to/needed to.

Such a script might look something like this:

#include "utility_h"
#include "wrappers_h"
#include "plt_dim_improved_item_plot"


void ProcessPlayerChoice(nButton)
{
    // pre-emption: there is a valid choice to process
    if(nButton == 0)
        return;
        
    // Get the player's Origin to determine which improved item to give                   
    object oHero = GetHero();  
    
    int nRace = GetCreatureRacialType(oHero);
    int nBackground = GetPlayerBackground(oHero);

    // Add the improved Warden's Oath amulet
    if(nButton == 2) UT_AddItemToInventory(R"dim_imp_wardensoath_low.uti", 1);
    if(nButton == 3) UT_AddItemToInventory(R"dim_imp_wardensoath.uti", 1);
    if(nButton == 4) UT_AddItemToInventory(R"dim_imp_wardensoath_high.uti", 1);
                                                                         
    switch(nBackground)
    {
        case 1:
        {
            // If the player is a Dalish Elf, add the improved Keeper's Ring
            if(nButton == 2) UT_AddItemToInventory(R"dim_imp_keepersring_low.uti", 1);
            if(nButton == 3) UT_AddItemToInventory(R"dim_imp_keepersring.uti", 1);
            if(nButton == 4) UT_AddItemToInventory(R"dim_imp_keepersring_high.uti", 1);
            break;
        }
        case 2:
        {
            // If the player is a Dwarf Commoner, add the improved Aeducan Mace
            if(nButton == 2) UT_AddItemToInventory(R"dim_imp_aeducanmace_low.uti", 1);
            if(nButton == 3) UT_AddItemToInventory(R"dim_imp_aeducanmace.uti", 1);
            if(nButton == 4) UT_AddItemToInventory(R"dim_imp_aeducanmace_high.uti", 1);
            break;
        }
        case 3:
        {   // If the player is a City Elf, add the improved Wedding Ring
            if(nButton == 2) UT_AddItemToInventory(R"dim_imp_weddingring_low.uti", 1);
            if(nButton == 3) UT_AddItemToInventory(R"dim_imp_weddingring.uti", 1);
            if(nButton == 4) UT_AddItemToInventory(R"dim_imp_weddingring_high.uti", 1);
            break;
        }
        case 4:
        {
            // If the player is a Circle Mage, add the improved Ring of Study 
            if(nButton == 2) UT_AddItemToInventory(R"dim_imp_ringofstudy_low.uti", 1);
            if(nButton == 3) UT_AddItemToInventory(R"dim_imp_ringofstudy.uti", 1);
            if(nButton == 4) UT_AddItemToInventory(R"dim_imp_ringofstudy_high.uti", 1);
            break;
        }
        case 5:
        {
            if(nRace == 1)  
            {
                // If the player is a Dwarf Noble, add the improved Aeducan Signet Ring
                if(nButton == 2) UT_AddItemToInventory(R"dim_imp_aeducanring_low.uti", 1);
                if(nButton == 3) UT_AddItemToInventory(R"dim_imp_aeducanring.uti", 1);
                if(nButton == 4) UT_AddItemToInventory(R"dim_imp_aeducanring_high.uti", 1);
            }
            else if(nRace == 3)  
            {
                // If the player is a Human Noble, add the improved Family Sword
                if(nButton == 2) UT_AddItemToInventory(R"dim_imp_familysword_low.uti", 1);
                if(nButton == 3) UT_AddItemToInventory(R"dim_imp_familysword.uti", 1);
                if(nButton == 4) UT_AddItemToInventory(R"dim_imp_familysword_high.uti", 1);
            }
            break; 
        }
        default: 
        {
            PrintToLog("Error: dim_improved_item_handler:  No valid origin");
            break;
        }
    }

    // set the completion flag as true so that it doesn't go into the script again
    WR_SetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG, TRUE);
}


//--------------------------------------------------------------------------------------------------
//  MAIN
//--------------------------------------------------------------------------------------------------

void main()
{ 
    event ev = GetCurrentEvent();

    switch(GetEventType(ev))
    {
        case EVENT_TYPE_POPUP_RESULT:
        {                                                         
            // stop event if we've already given the items
            if(WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG))
                return;

            int nButton = GetEventInteger(ev, 1); 
            ProcessPlayerChoice(nButton);
        }
        case EVENT_TYPE_MODULE_LOAD:
        case EVENT_TYPE_CHARGEN_END:
        {
            // stop event if we've already given the items
            if(WR_GetPlotFlag(PLT_DIM_IMPROVED_ITEM_PLOT, DIM_ALL_ITEM_FLAG))
                return;

            ShowPopup(1205465333, 15700);
        }
        default:
        {
            PrintToLog("Error: dim_improved_item_handler:  No applicable event");
            break;
        }
    }
}

Note the above is just for illustration purposes and has not been compiled let alone tested!

Modifié par Sunjammer, 12 décembre 2009 - 03:43 .


#13
NSIBystander

NSIBystander
  • Members
  • 18 messages
Ahh, I see what you mean. Yes, that makes a whole lot of sense to do. Thanks a bunch for the advice.