Author Topic: Unknown Error with script  (Read 617 times)

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« on: December 21, 2010, 01:28:01 pm »


                void main(){    object oPC = GetEnteringObject();    if(!GetIsPC(oPC)) return;// Check Equip Items and get rid of them    int i;    for(i=0; i<14; i++)    {    object oEquip = GetItemInSlot(i,oPC);    if(GetIsObjectValid(oEquip))        {        SetPlotFlag(oEquip,FALSE);        DestroyObject(oEquip);        }    }// Check general Inventory and clear it out.    object oItem = GetFirstItemInInventory(oPC);    while(GetIsObjectValid(oItem))        {        SetPlotFlag(oItem,FALSE);        DestroyObject(oItem);        oItem = GetNextItemInInventory(oPC);        }//Give them Gold    string sclass = GetclassByPosition(1,oPC);   <<<<<<<<<<<<<<Mismatched types error here.    if (sclass = "class_TYPE_BARBARIAN")    {        string sArmour = "hidearmour";        string sWeapon = "handaxe";        string sOther = "sling";        CreateItemOnObject("bullet", oPC);    }    if (sclass = "class_TYPE_SORCEROR")    {        string sArmour = "plainrobe";        string sWeapon = "staff";        string sOther = "ringofinsight";    }    if (sclass = "class_TYPE_WIZARD")    {        string sArmour = "plainrobe";        string sWeapon = "staff";        string sOther = "ringofinsight";    }    if (sclass = "class_TYPE_DRUID")    {        string sArmour = "plainrobe";        string sWeapon = "staff";        string sOther = "sickleberry";    }    if (sclass = "class_TYPE_MONK")    {        string sArmour = "plainrobe";        string sWeapon = "staff";        string sOther = "medicinalherb";    }    if (sclass = "class_TYPE_BARD")    {        string sArmour = "plainrobe";        string sWeapon = "staff";        string sOther = "medicinalherb";    }    if (sclass = "class_TYPE_FIGHTER")    {        string sArmour = "heavyleather";        string sWeapon = "longsword";        string sOther = "smallshield";    }    if (sclass = "class_TYPE_PALADIN")    {        string sArmour = "chainmail";        string sWeapon = "greatsword";        string sOther = "ringoftheorder";    }    if (sclass = "class_TYPE_RANGER")    {        string sArmour = "leatherarmour";        string sWeapon = "shortbow";        string sOther = "arrow";    }    CreateItemOnObject(sArmour, oPC);    CreateItemOnObject(sWeapon, oPC);    CreateItemOnObject(sOther, oPC);    CreateItemOnObject("medicinalherb", oPC);    CreateItemOnObject("medicinalherb", oPC);    CreateItemOnObject("medicinalherb", oPC);}

This is my code.
What's wrong with it?'<img'>
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Unknown Error with script
« Reply #1 on: December 21, 2010, 01:53:14 pm »


               GetclassByPosition is used in this way, as an example.

int iclass = GetclassByPosition(1, oPC);


You are attempting to use it as a string, when the function returns a number. This is incorrect.

If you use the above example, the following checks would look like this -

if (iclass == class_TYPE_BARBARIAN)

{
DO STUFF HERE
}



EDIT: Please be aware of the forum. It removes the uppercase on "class", so if you copy and paste either line, you will have to fix it in your script. The "class" in GetclassByPoint requires a capital C as well.

FP!
               
               

               


                     Modifié par Fester Pot, 21 décembre 2010 - 02:08 .
                     
                  


            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #2 on: December 21, 2010, 04:56:17 pm »


               Right, so I use it as an integer not string? Thanks Fester and sorry that my code went all wierd, I'm glad you could still understand, and thanks for the warning about class. Why DOES it do that?
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #3 on: December 21, 2010, 05:03:48 pm »


               now I have a different issue. I figured because the class_TYPE_* are int not string I had to remove the quotations, so now I have this:


void main()
{
   object oPC = GetEnteringObject();
   if(!GetIsPC(oPC)) return;
// Check Equip Items and get rid of them
   int i;
   for(i=0; i
   {
   object oEquip = GetItemInSlot(i,oPC);
   if(GetIsObjectValid(oEquip))
       {
       SetPlotFlag(oEquip,FALSE);
       DestroyObject(oEquip);
       }
   }
// Check general Inventory and clear it out.
   object oItem = GetFirstItemInInventory(oPC);
   while(GetIsObjectValid(oItem))
       {
       SetPlotFlag(oItem,FALSE);
       DestroyObject(oItem);
       oItem = GetNextItemInInventory(oPC);
       }
//Give them Gold
   int iclass = GetclassByPosition(1,oPC);
   if (iclass == class_TYPE_BARBARIAN)
   {
       string sArmour = "hidearmour";
       string sWeapon = "handaxe";
       string sOther = "sling";
       CreateItemOnObject("bullet", oPC);
   }
   if (iclass == class_TYPE_SORCEROR)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "ringofinsight";
   }
   if (iclass == class_TYPE_WIZARD)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "ringofinsight";
   }
   if (iclass == class_TYPE_DRUID)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "sickleberry";
   }
   if (iclass == class_TYPE_MONK)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "medicinalherb";
   }
   if (iclass == class_TYPE_BARD)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "medicinalherb";
   }
   if (iclass == class_TYPE_FIGHTER)
   {
       string sArmour = "heavyleather";
       string sWeapon = "longsword";
       string sOther = "smallshield";
   }
   if (iclass == class_TYPE_PALADIN)
   {
       string sArmour = "chainmail";
       string sWeapon = "greatsword";
       string sOther = "ringoftheorder";
   }
   if (iclass == class_TYPE_RANGER)
   {
       string sArmour = "leatherarmour";
       string sWeapon = "shortbow";
       string sOther = "arrow";
   }
   CreateItemOnObject(sArmour, oPC);
   CreateItemOnObject(sWeapon, oPC);
   CreateItemOnObject(sOther, oPC);
   CreateItemOnObject("medicinalherb", oPC);
   CreateItemOnObject("medicinalherb", oPC);
   CreateItemOnObject("medicinalherb", oPC);
}


so how do I fix that?
               
               

               


                     Modifié par Dylmani555, 21 décembre 2010 - 08:52 .
                     
                  


            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Unknown Error with script
« Reply #4 on: December 21, 2010, 05:53:01 pm »


               Missing some caps:


GetclassByPosition

class_TYPE_*

Also you misspelled "sorcerer"

class_TYPE_SORCERER

The compiler is sensitive to that kind of ting. I recommend using the window on the right in the script editor to find the functions/constants you want then double click to add them to your code. That way you make sure everything is capitalized and spelled correctly.

-420

EDIT: It seems BioWare's forum is forcing the word "class" to be lower case. I swear this is the worst forum ever. Why can't we go back to the old forums? Is BioWare trying to get rid of us?

EDIT EDIT: Argh BioWare you SUCK! OK, so anyway I'm guessing you did get the capitalization right and BioWare's foums are just screwing it up. So most likely your only problem is the spelling of sorcerer.
               
               

               


                     Modifié par 420, 21 décembre 2010 - 05:59 .
                     
                  


            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #5 on: December 21, 2010, 06:10:00 pm »


               oh, so it's because I misspelled something xD Thanks 420



I preferred the *ahem* "Legacy" forums too. '<img'>
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #6 on: December 21, 2010, 06:14:15 pm »


               Aargh! it's just 1 error after another!:


void main()
{
   object oPC = GetEnteringObject();
   if(!GetIsPC(oPC)) return;
// Check Equip Items and get rid of them
   int i;
   for(i=0; i
   {
   object oEquip = GetItemInSlot(i,oPC);
   if(GetIsObjectValid(oEquip))
       {
       SetPlotFlag(oEquip,FALSE);
       DestroyObject(oEquip);
       }
   }
// Check general Inventory and clear it out.
   object oItem = GetFirstItemInInventory(oPC);
   while(GetIsObjectValid(oItem))
       {
       SetPlotFlag(oItem,FALSE);
       DestroyObject(oItem);
       oItem = GetNextItemInInventory(oPC);
       }
//Give them Gold
   int iclass = GetclassByPosition(1,oPC);
   if (iclass == class_TYPE_BARBARIAN)
   {
       string sArmour = "hidearmour";
       string sWeapon = "handaxe";
       string sOther = "sling";
       CreateItemOnObject("bullet", oPC);
   }
   if (iclass == class_TYPE_SORCERER)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "ringofinsight";
   }
   if (iclass == class_TYPE_WIZARD)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "ringofinsight";
   }
   if (iclass == class_TYPE_DRUID)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "sickleberry";
   }
   if (iclass == class_TYPE_MONK)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "medicinalherb";
   }
   if (iclass == class_TYPE_BARD)
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "medicinalherb";
   }
   if (iclass == class_TYPE_FIGHTER)
   {
       string sArmour = "heavyleather";
       string sWeapon = "longsword";
       string sOther = "smallshield";
   }
   if (iclass == class_TYPE_PALADIN)
   {
       string sArmour = "chainmail";
       string sWeapon = "greatsword";
       string sOther = "ringoftheorder";
   }
   if (iclass == class_TYPE_RANGER)
   {
       string sArmour = "leatherarmour";
       string sWeapon = "shortbow";
       string sOther = "arrow";
   }
   else
   {
       string sArmour = "plainrobe";
       string sWeapon = "staff";
       string sOther = "medicinalherb";
   }
   CreateItemOnObject(sArmour, oPC);
   CreateItemOnObject(sWeapon, oPC);
   CreateItemOnObject(sOther, oPC);
   CreateItemOnObject("medicinalherb", oPC);
   CreateItemOnObject("medicinalherb", oPC);
   CreateItemOnObject("medicinalherb", oPC);
}
               
               

               


                     Modifié par Dylmani555, 21 décembre 2010 - 08:52 .
                     
                  


            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Unknown Error with script
« Reply #7 on: December 21, 2010, 07:12:42 pm »


               That is a slightly more complicated fix. The problem is that you are declaring variables in if statements. All your variables should be declared at the beginning of the script like so:

void main()
{
object oPC = GetEnteringObject();
object oEquip;
int iclass;
string sArmour;
string sWeapon;
string sOther;

Then you need to remove the "object", "int" and "string" from the beginning of the rest of the variables.

For example:

for(i=0; i<14; i++)
{
oEquip = GetItemInSlot(i,oPC);
if(GetIsObjectValid(oEquip))
{
SetPlotFlag(oEquip,FALSE);
DestroyObject(oEquip);
}
}

and

iclass = GetclassByPosition(1,oPC);
if (iclass == class_TYPE_BARBARIAN)
{
sArmour = "hidearmour";
sWeapon = "handaxe";
sOther = "sling";

        CreateItemOnObject("bullet", oPC);
}

-420
               
               

               


                     Modifié par 420, 21 décembre 2010 - 07:14 .
                     
                  


            

Legacy_ent.devil

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
Unknown Error with script
« Reply #8 on: December 21, 2010, 07:16:30 pm »


               This is because the code in the curly brackets is a distinct scope, so when you define something inside it that scope then it can't be used outside of it, hence why there aren't any errors thrown about multiple declarations of sArmour, sWeapon and sStaff.

I would just define then at the top of the script by the oPC assignment and then the correct value for the situation in your if blocks.

One other thing it seems that you are doing something like this:

if () {

}

if () {

}

if () {

} else {

}

when you could do with something like this otherwise a class that matches an earlier value will be altered by that last else block:

if () {

} else if () {

} else if () {

} else if () {

} else {

}

or even use a switch statement, which ever is easier for you to follow:

switch(GetclassByPosition(1, oPC)) {
  case class_TYPE_BARBARIAN:
    sArmour = "blah";
    sWeapon = "blah";
    sOther = "blah";
    CreateItemOnObject("blah", oPC);
    break;
  case class_TYPE_FIGHTER:
    sArmour = "blah";
    sWeapon = "blah";
    sOther = "blah";
    break;
// and all the other classes
  default:
    sArmour = "plainrobe";
    sWeapon = "staff";
    sOther = "medicinalherb";
    break;
}

CreateItemOnObject(sArmour, oPC);


etc....
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Unknown Error with script
« Reply #9 on: December 21, 2010, 07:16:44 pm »


               The reason it was erroring was that you only defined the item strings INSIDE an if bracket, but used them outside any if bracket - creating instances where they were used without being defined. I fixed that by moving the declarations to before the if/elses. I then converted your if's to a switch statement, to save lines and to minimize the number of 'class' capitalizations you'd have to fix. For the same reason, I changed all the class consts to their numbers, with comments. As it stands now, the only one you'll have to recapitalize to fix the forum changes is the GetclassByPosition function.

More notes: 
-do NOT use quick reply when posting scripts, it separates each line and destroys indenting, making scripts a pain to read.
-the script below has redundant cases - cases identical to the default case (monk and bard). I left them in case you wanted to change gear handouts for monk and bard in the future.
Here's a working script for you:

void main() {

    object oPC = GetEnteringObject();
    if(!GetIsPC(oPC))
        return;

    // Check Equip Items and get rid of them

    int i;
    for(i=0; i<14; i++) {

        object oEquip = GetItemInSlot(i,oPC);
        if(GetIsObjectValid(oEquip)) {
            SetPlotFlag(oEquip,FALSE);
            DestroyObject(oEquip);
        }
    }

    // Check general Inventory and clear it out.
    object oItem = GetFirstItemInInventory(oPC);
    while(GetIsObjectValid(oItem)) {
        SetPlotFlag(oItem,FALSE);
        DestroyObject(oItem);
        oItem = GetNextItemInInventory(oPC);
    }

    //Give them Items
    string sArmour, sWeapon, sOther;

    int nclass = GetclassByPosition(1,oPC);
    switch(nclass) {
        case 0://BARBARIAN
        sArmour = "hidearmour";
        sWeapon = "handaxe";
        sOther = "sling";
        CreateItemOnObject("bullet", oPC);
        break;
        case 9://SORCERER
        case 10://WIZARD - no break means case 9 and 10 will be the same
        sArmour = "plainrobe";
        sWeapon = "staff";
        sOther = "ringofinsight";
        break;
        case 3://DRUID
        sArmour = "plainrobe";
        sWeapon = "staff";
        sOther = "sickleberry";
        break;
        case 4://FIGHTER
        sArmour = "heavyleather";
        sWeapon = "longsword";
        sOther = "smallshield";
        break;
        case 6://PALADIN
        sArmour = "chainmail";
        sWeapon = "greatsword";
        sOther = "ringoftheorder";
        break;
        case 7://RANGER
        sArmour = "leatherarmour";
        sWeapon = "shortbow";
        sOther = "arrow";
        break;
        case 5://MONK
        case 1://BARD - two missing breaks - don't even need these cases
        default:
        sArmour = "plainrobe";
        sWeapon = "staff";
        sOther = "medicinalherb";
        break;
    }

    CreateItemOnObject(sArmour, oPC);
    CreateItemOnObject(sWeapon, oPC);
    CreateItemOnObject(sOther, oPC);
    CreateItemOnObject("medicinalherb", oPC);
    CreateItemOnObject("medicinalherb", oPC);
    CreateItemOnObject("medicinalherb", oPC);
}

Funky
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #10 on: December 21, 2010, 07:20:39 pm »


               wow 3 replies, I found 420's the easiest to understand, just define the variables earlier on with no value right?



Thanks guys '<img'>
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #11 on: December 21, 2010, 07:28:32 pm »


               Thanks to you guys, I finally have the script working '<img'>
I will put Fester Pot and 420's names in the credits

for anyone who is interested, here is the final script:



void main()
{
   object oPC = GetEnteringObject();
   if(!GetIsPC(oPC)) return;
// Check Equip Items and get rid of them
   int i;
   for(i=0; i
   {
   object oEquip = GetItemInSlot(i,oPC);
   if(GetIsObjectValid(oEquip))
       {
       SetPlotFlag(oEquip,FALSE);
       DestroyObject(oEquip);
       }
   }
// Check general Inventory and clear it out.
   object oItem = GetFirstItemInInventory(oPC);
   while(GetIsObjectValid(oItem))
       {
       SetPlotFlag(oItem,FALSE);
       DestroyObject(oItem);
       oItem = GetNextItemInInventory(oPC);
       }
//Give them Gold
   int iclass = GetclassByPosition(1,oPC);
   string sArmour;
   string sWeapon;
   string sOther;
   if (iclass == class_TYPE_BARBARIAN)
   {
       sArmour = "hidearmour";
       sWeapon = "handaxe";
       sOther = "sling";
       CreateItemOnObject("bullet", oPC);
   }
   if (iclass == class_TYPE_SORCERER)
   {
       sArmour = "plainrobe";
       sWeapon = "staff";
       sOther = "ringofinsight";
   }
   if (iclass == class_TYPE_WIZARD)
   {
       sArmour = "plainrobe";
       sWeapon = "staff";
       sOther = "ringofinsight";
   }
   if (iclass == class_TYPE_DRUID)
   {
       sArmour = "plainrobe";
       sWeapon = "staff";
       sOther = "sickleberry";
   }
   if (iclass == class_TYPE_MONK)
   {
       sArmour = "plainrobe";
       sWeapon = "staff";
       sOther = "medicinalherb";
   }
   if (iclass == class_TYPE_BARD)
   {
       sArmour = "plainrobe";
       sWeapon = "staff";
       sOther = "medicinalherb";
   }
   if (iclass == class_TYPE_FIGHTER)
   {
       sArmour = "heavyleather";
       sWeapon = "longsword";
       sOther = "smallshield";
   }
   if (iclass == class_TYPE_PALADIN)
   {
       sArmour = "chainmail";
       sWeapon = "greatsword";
       sOther = "ringoftheorder";
   }
   if (iclass == class_TYPE_RANGER)
   {
       sArmour = "leatherarmour";
       sWeapon = "shortbow";
       sOther = "arrow";
   }
   CreateItemOnObject(sArmour, oPC);
   CreateItemOnObject(sWeapon, oPC);
   CreateItemOnObject(sOther, oPC);
   CreateItemOnObject("medicinalherb", oPC);
   CreateItemOnObject("medicinalherb", oPC);
   CreateItemOnObject("medicinalherb", oPC);
}


this replaces the original script on the OnClientEnter event of module properties.


Enjoy '<img'>
               
               

               


                     Modifié par Dylmani555, 21 décembre 2010 - 08:52 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Unknown Error with script
« Reply #12 on: December 21, 2010, 07:33:33 pm »


               You didn't even read mine, it seems:

FunkySwerve wrote...

-do NOT use quick reply when posting scripts, it separates each line and destroys indenting, making scripts a pain to read.


               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #13 on: December 21, 2010, 08:51:39 pm »


               That was why I WAS using quick reply, it separates the lines, rather than my first post.
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Unknown Error with script
« Reply #14 on: December 21, 2010, 08:56:28 pm »


               

ent.devil wrote...
One other thing it seems that you are doing something like this:

if () {
}
if () {
}
if () {
} else {
}

when you could do with something like this otherwise a class that matches an earlier value will be altered by that last else block:

if () {
} else if () {
} else if () {
} else if () {
} else {
}


I take it you would prefer to use the second method shown here as it will only check the later classes if the earlier ones show false, but as it is only checking the first class, only 1 can be true.'^_^'