Author Topic: Weird issue with virtually identical code  (Read 625 times)

Legacy_Wallack

  • Full Member
  • ***
  • Posts: 221
  • Karma: +0/-0
Weird issue with virtually identical code
« on: April 19, 2016, 09:50:35 am »


               

Here's the thing.


I have a vendor with a store (tag and resref "vacio" which means empty in Spanish) and 6 signs. Each sign has a script attached to the onuse, they go from test 5 to test 9b (test5, 6, 7, 8, 9 and 9b) last one is 9b instead of 10 because I even tried to name it diferently to see if there was any problem.


Each of those scripts are very simple. They gather the location of the store waypoint, they destroy it and create a new one instead. Then they call a function in inc_utils that is called GenerarTiendaAleatoria (GenerateRandomShop). They same the same parameters excep the last one (iRango). That determines the quality of the items to randomly generate.


I use commche's random item generator (which I'm going to rewrite but that's another thing) and functions of this system are used by GenerarTiendaAleatoria.


GenerarTiendaAleatoria checks if the object is valid, if is a store yada yada, and then tries to DropArmor on the store.


Here's the thing, it works for test5 to test9 but not on test 9b. Now you can see the code for DropArmor with a DelayCommand. Without the delay command I get no error, but the store is empty. With the delay command I get the error that the object sent is not a store. Here's the initial part for the Drop Armor function:


oMon id not used at all in the overall function, iRange is not used when it fails so it doesn't matter that the parameter is different. It fails when showing the message "Error tienda2 antes crear" which means "Shop error 2 before creating". That means that the object sent as a Store is not a store.


If I don't do the delaycommand it seems to work (no errors) but the store is empty. If I do the delay command the error is thrown there. Keep in mind that it doesn't matter if I use delaycommand or not, it works on the other 5 signs.



void DropArmor(object oMob, object oSack, int iRange, int SockChance, int iChest)
{
    object oItem;
    itemproperty ipAdd;
    string sType, sIName, sName, sSocks;
    int iQual = 0;
    int iRoll = d10();
    switch (iRoll)
    {
        case 1: sType = "sdarmor8"; sIName = "Plate"; break;
        case 2: sType = "sdarmor7"; sIName = "Half Plate"; break;
        case 3: sType = "sdarmor6"; sIName = "Chain Mail"; break;
        case 4: sType = "sdarmor5"; sIName = "Banded Mail"; break;
        case 5: sType = "sdarmor4"; sIName = "Breastplate"; break;
        case 6: sType = "sdarmor3"; sIName = "Studded Leather"; break;
        case 7: sType = "sdarmor2"; sIName = "Hardened Leather"; break;
        case 8: sType = "sdarmor1"; sIName = "Leather"; break;
        case 9: sType = "sdarmor0"; sIName = "Tunic"; break;
        case 10: sType = "sdarmor02"; sIName = "Robe"; break;
    }
    object oPC = GetLastUsedBy();
    if(oSack == OBJECT_INVALID)
    {
        SendMessageToPC(oPC, "Error tienda1 antes crear");
        return;
    }
    if(GetObjectType(oSack) != OBJECT_TYPE_STORE)
    {
        SendMessageToPC(oPC, "Error tienda2 antes crear");
        return;
    }
    if(GetHasInventory(oSack) == FALSE)
    {
        SendMessageToPC(oPC, "Error tienda3 antes crear");
        return;
    }
    SendMessageToPC(oPC, "Generando armadura de tipo " + sType);
    oItem = CreateItemOnObject(sType, oSack, 1, "sf_socket_item");
    if(oSack == OBJECT_INVALID)
    {
        SendMessageToPC(oPC, "Error tienda1");
        return;
    }
    if(GetObjectType(oSack) != OBJECT_TYPE_STORE)
    {
        SendMessageToPC(oPC, "Error tienda2");
        return;
    }
    if(GetHasInventory(oSack) == FALSE)
    {
        SendMessageToPC(oPC, "Error tienda3");
        return;
    }
    if(oItem == OBJECT_INVALID)
    {
        SendMessageToPC(oPC, "Error armadura");
        return;
    }


Here is the content of each test file:



void main()
{
    object oPC = GetLastUsedBy();
    object oTienda = GetNearestObjectByTag("vacio");
    location lLoc = GetLocation(oTienda);
    DestroyObject(oTienda);
    CreateObject(OBJECT_TYPE_STORE, "vacio", lLoc, FALSE, "vacio");
    oTienda = GetNearestObjectByTag("vacio");
    GenerarTiendaAleatoria(oTienda, 5, 5, 5, 5, 1);
}


It only varies in the last number, the 1 is a 6 in the test9b. Is like, somehow, test9b deletes and recreates the store object or something, because the store object doesn't exists (with the delay command) as a store when adding the items but it exists because you can browse the merchant.


Here is the link with the module: http://wallack.es/ar...os/testings.zip


I lost my mind yesterday around this, I still have no idea. This was a small test to generate diferently random items with different qualities for my vendors and ate my whole day yesterday.


My next approach will be to keep the signs to just add items to the vendor and then have a different placeable to delete the store and recreate it.


If you ask why I destroy and recreate the vendor instead of removing the items, is mostly because I don't want it to place the stuff in weird positions when browsing the vendor.


Maybe one of you can find an answer to this mistery or at least join me in my misery.


Thank you very much.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Weird issue with virtually identical code
« Reply #1 on: April 19, 2016, 11:36:32 pm »


               

I am looking at what I think is the relevant information.


 


 




They same the same parameters except the last one (iRango). That determines the quality of the items to randomly generate.


I use commche's random item generator (which I'm going to rewrite but that's another thing) and functions of this system are used by GenerarTiendaAleatoria.


GenerarTiendaAleatoria checks if the object is valid, if is a store yada yada, and then tries to DropArmor on the store.


Here's the thing, it works for test5 to test9 but not on test 9b.

 



GenerarTiendaAleatoria(oTienda, 5, 5, 5, 5, 1);

It only varies in the last number, the 1 is a 6 in the test9b. Is like, somehow, test9b deletes and recreates the store object or something, because the store object doesn't exists (with the delay command) as a store when adding the items but it exists because you can browse the merchant.

 




 


It appears that 6 might be an invalid quality, and thus objects are unable to be produced with that setting.



               
               

               
            

Legacy_Wallack

  • Full Member
  • ***
  • Posts: 221
  • Karma: +0/-0
Weird issue with virtually identical code
« Reply #2 on: April 20, 2016, 09:35:42 am »


               

Nah, that's not it, even using the same script in the onused did fail. The quality goes from 1 to 8 and is not used at all in that stage of the script, I did that function so it doesn't really matter.


 


I went with a different approach. Each of the placeables now just create the items in the store and then a 7th placeable will destroy and recreate the store so I can test it nicely, it was just a really weird issue :S