Author Topic: Giving items depending on class not working  (Read 375 times)

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« on: April 20, 2012, 08:33:27 pm »


               Here's my code:
 

if (GetclassByPosition(1, oPC)) == class_TYPE_BARBARIAN(
        string sArmour = "hidearmour";
        string sWeapon = "battleaxe";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_BARD(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_CLERIC(
        string sArmour = "plainrobe";
        string sWeapon = "mace";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_DRUID(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_FIGHTER(
        string sArmour = "heavyleather";
        string sWeapon = "longsword";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_MONK(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_PALADIN(
        string sArmour = "chainmail";
        string sWeapon = "longsword";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_RANGER(
        string sArmour = "leatherarmour";
        string sWeapon = "longsword";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_ROGUE(
        string sArmour = "paddedcloth";
        string sWeapon = "dagger";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_SORCEROR(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    if (GetclassByPosition(1, oPC)) == class_TYPE_WIZARD(
        string sArmour = "plainrobe";
        string sWeapon = "staff";
    )
    CreateItemOnObject(sArmour, oPC);
    CreateItemOnObject(sWeapon, oPC);
    CreateItemOnObject(medicinalherb, oPC);
    CreateItemOnObject(medicinalherb, oPC);
    CreateItemOnObject(medicinalherb, oPC);
}
Here's my problem, I get the error of "UNKNOWN STATE IN THE COMPILER" on the first line of this snippet, also whenever I enter, regardless of my class, I am given a plainrobe and a staff.

Whats going wrong? the variable names for the classes were taken directly from Lexicon.':crying:'
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #1 on: April 20, 2012, 08:34:18 pm »


               By the way all of the caps in the class words are fine, it's just this forum is messed up and always puts it in no caps
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #2 on: April 20, 2012, 08:36:51 pm »


               Also, in case it's like some compilers where it shows the error on the line AFTER the line that is wrong, heres the line above this code snippet:
GiveGoldToCreature(oPC, 100);
thats right though isn't it?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Giving items depending on class not working
« Reply #3 on: April 20, 2012, 09:30:07 pm »


               
if (GetclassByPosition(1, oPC)[color="#ff0000"])[/color] == class_TYPE_BARBARIAN[color="#ff0000"]([/color]
        string sArmour = "hidearmour";
        string sWeapon = "battleaxe";
)


Should be:

if (GetclassByPosition(1, oPC) == class_TYPE_BARBARIAN[color="#99cc00"])[/color]
[color="#99cc00"]{[/color]
        string sArmour = "hidearmour";
        string sWeapon = "battleaxe";
    [color="#99cc00"]}[/color]

'<img'>
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #4 on: April 20, 2012, 11:00:26 pm »


               failure of epic proportions, thanks GhostOfGod, I'll fix that on all 12 or so If statements
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #5 on: April 20, 2012, 11:02:45 pm »


               damn, I did that.. but the error remains...
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Giving items depending on class not working
« Reply #6 on: April 21, 2012, 01:31:56 am »


               Did you also notice the change from parentheses to the curley brackets?
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Giving items depending on class not working
« Reply #7 on: April 21, 2012, 08:05:41 am »


               I think you should also declare your string variables before all 'if' statements:

string sArmour, sWeapon;
int nclass = GetclassByPosition(1, oPC);
if (nclass == class_TYPE_BARBARIAN)
{
sArmour = "hidearmour";
sWeapon = "battleaxe";
}
else if(nclass == class_TYPE_BARD)
{
sArmour = "plainrobe";
sWeapon = "staff";
}
etc.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Giving items depending on class not working
« Reply #8 on: April 21, 2012, 03:48:29 pm »


               

Alex Warren wrote...

I think you should also declare your string variables before all 'if' statements:

string sArmour, sWeapon;
int nclass = GetclassByPosition(1, oPC);
if (nclass == class_TYPE_BARBARIAN)
{
sArmour = "hidearmour";
sWeapon = "battleaxe";
}
else if(nclass == class_TYPE_BARD)
{
sArmour = "plainrobe";
sWeapon = "staff";
}
etc.


I bet you nailed that one.  NWScript does allow for a variable name to be used multiple times,

e.g.

void main()
{
string sVar = "10";
if(TRUE)
  {
  string sVar = "5";
  SendMessageToPC(OBJECT_SELF, sVar);
  }
SendMessageToPC(OBJECT_SELF, sVar);
}

would send the messages of "5" and then "10".  The declaration inside the braces of the if clause {}overides the outside declaration only within those braces.
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #9 on: April 21, 2012, 08:53:06 pm »


               I thkn I know what it is, in the if statement, the second parenthises after the oPC variable.. I didn't remove it '<img'>
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #10 on: April 21, 2012, 08:58:46 pm »


               Also I mis-spelt Sorcerer as Sorceror '<img'>
               
               

               
            

Legacy_Dylmani555

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-0
Giving items depending on class not working
« Reply #11 on: April 27, 2012, 06:12:04 pm »


               Yup it all works now, thanks guys '<img'>