Author Topic: math operators confusion  (Read 1298 times)

Code: [Select]
if(%team $="jedi")
                {
                switch (1)
                {
                case %level>=0:
         %rank = "Youngling";
                case %level>=20:
         %rank = "Initiate";
                case %level>=50:
         %rank = "Padawan";
          case %level>=250:
         %rank = "Knight";
        case %level>=500:
         %rank = "Master";
          case %level>=750:
         %rank = "Grand Master";

This doesn't work im level 26 and it still says im a Youngling?

The switch is wrong and that's not going to work. You'd probably want to use an if statement for what you're trying to do here.

The switch is wrong and that's not going to work. You'd probably want to use an if statement for what you're trying to do here.
What would be the correct way to do that

if(%level < 20)
     %rank = "youngling";
else if(%level < 50)
     %rank = "initiate";

//other ranks here

else if(%level >= 750)
     %rank = "grand master";

etc etc
« Last Edit: May 13, 2017, 02:38:09 AM by PhantOS »

The cases in a switch statement only check for for specific values, not ranges of values. Otherwise, there wouldn't really be much that differentiated switches statements from if-else chains. Check out the official TorqueScript reference for a refresher: http://docs.garagegames.com/torque-3d/official/content/documentation/Scripting/Simple/Switch.html

The cases in a switch statement only check for for specific values, not ranges of values. Otherwise, there wouldn't really be much that differentiated switches statements from if-else chains. Check out the official TorqueScript reference for a refresher: http://docs.garagegames.com/torque-3d/official/content/documentation/Scripting/Simple/Switch.html
Oh I see.
So if his level is 23, to the computer his switch statement looks like this:
Code: [Select]
switch (1)
                {
                case 1:
         %rank = "Youngling";
                case 1:
         %rank = "Initiate";
                case 0:
         %rank = "Padawan";
         case 0:
         %rank = "Knight";
         case 0:
         %rank = "Master";
         case 0:
         %rank = "Grand Master";
And the game leaves the switch statement at the first success.

Why not just reverse the order?
Code: [Select]
switch (1)
{
        case %level>=750:
                %rank = "Grand Master";
        case %level>=500:
                %rank = "Master";
        case %level>=250:
                %rank = "Knight";
        case %level>=50:
                %rank = "Padawan";
        case %level>=20:
                %rank = "Initiate";
        case %level>=0:
                %rank = "Youngling";
That way it will exit the switch as soon as it hits the highest rank the person qualifies for.
« Last Edit: May 13, 2017, 11:21:13 AM by Tendon »

if(%level < 20)
     %rank = "youngling";
else if(%level < 50)
     %rank = "initiate";

//other ranks here

else if(%level >= 750)
     %rank = "grand master";

etc etc
Code: [Select]
if(%team $="jedi")
                {
        if %level>=750:
                %rank = "Grand Master";

This doesnt seem right because I want it to check if there on team sith or team jedi

just use if else instead of raping the switch/case system

Oh I see.
So if his level is 23, to the computer his switch statement looks like this:
Code: [Select]
switch (1)
                {
                case 1:
         %rank = "Youngling";
                case 1:
         %rank = "Initiate";
                case 0:
         %rank = "Padawan";
         case 0:
         %rank = "Knight";
         case 0:
         %rank = "Master";
         case 0:
         %rank = "Grand Master";
And the game leaves the switch statement at the first success.

Why not just reverse the order?
Code: [Select]
switch (1)
{
        case %level>=750:
                %rank = "Grand Master";
        case %level>=500:
                %rank = "Master";
        case %level>=250:
                %rank = "Knight";
        case %level>=50:
                %rank = "Padawan";
        case %level>=20:
                %rank = "Initiate";
        case %level>=0:
                %rank = "Youngling";
That way it will exit the switch as soon as it hits the highest rank the person qualifies for.
this looks awful backwards and confusing else if would be a far better option



Code: [Select]
if(%team $="jedi")
                {
        if %level>=750:
                %rank = "Grand Master";

This doesnt seem right because I want it to check if there on team sith or team jedi

just add another if statement, and work on properly intending your code
like

Code: [Select]
if(%team $= "jedi")
{
if(%level < 20)
{
%rank = "youngling";
}
else if(%level < 50)
{
%rank = "initiate";
}
//more ranks here
}
else if(%team $= "sith lord")
{
//ranks here
}

also you may want to consider using variables on players or the client or something so these variables are persistent
ie

%client.team %client.level  and then pass in a client or player on your function