Aller au contenu

Photo

Unknown Error with script


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

#1
Dylmani555

Dylmani555
  • Members
  • 48 messages
 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?:(

#2
Fester Pot

Fester Pot
  • Members
  • 1 394 messages
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 .


#3
Dylmani555

Dylmani555
  • Members
  • 48 messages
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?

#4
Dylmani555

Dylmani555
  • Members
  • 48 messages
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 .


#5
420

420
  • Members
  • 190 messages
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 .


#6
Dylmani555

Dylmani555
  • Members
  • 48 messages
oh, so it's because I misspelled something xD Thanks 420



I preferred the *ahem* "Legacy" forums too. :(

#7
Dylmani555

Dylmani555
  • Members
  • 48 messages
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 .


#8
420

420
  • Members
  • 190 messages
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 .


#9
ent.devil

ent.devil
  • Members
  • 13 messages
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....

#10
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
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

#11
Dylmani555

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



Thanks guys ;)

#12
Dylmani555

Dylmani555
  • Members
  • 48 messages
Thanks to you guys, I finally have the script working :D
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 ;)

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


#13
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages
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.



#14
Dylmani555

Dylmani555
  • Members
  • 48 messages
That was why I WAS using quick reply, it separates the lines, rather than my first post.

#15
Dylmani555

Dylmani555
  • Members
  • 48 messages

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.^_^

#16
FunkySwerve

FunkySwerve
  • Members
  • 1 308 messages

Dylmani555 wrote...

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


The problem there was not the codebox or the lack of quick reply, it was the original formatting of the script you posted. See the script in my reply for what a properly formatted codeboxed script looks like (notice the preserved indents).

Funky

Modifié par FunkySwerve, 21 décembre 2010 - 10:34 .


#17
420

420
  • Members
  • 190 messages

Dylmani555 wrote...

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.^_^

Actually, if you don't use the "else" the script will run every "if" statement even after one has returned true. It's a minor adjustment but it makes a bigger difference in larger scripts.

-420